All Projects → salmanzafar949 → laravel-jwt-auto-installer

salmanzafar949 / laravel-jwt-auto-installer

Licence: MIT license
A Laravel Library that let's you add tymon jwt auth library and all it's features with single command

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-jwt-auto-installer

Backup
MySQL Database backup package for Laravel
Stars: ✭ 66 (+247.37%)
Mutual labels:  laravel-framework, laravel-package
Admin One Laravel Dashboard
Admin One — Free Laravel Dashboard (Bulma Buefy Vue.js SPA)
Stars: ✭ 94 (+394.74%)
Mutual labels:  laravel-framework, laravel-package
Laraupdater
Enable Laravel App Self-Update. Allow your Laravel Application to auto-update itself.
Stars: ✭ 75 (+294.74%)
Mutual labels:  laravel-framework, laravel-package
Laravel Open Source Projects
A Web Artisan list of categorized OPEN SOURCE PROJECTS built with Laravel PHP Framework.
Stars: ✭ 676 (+3457.89%)
Mutual labels:  laravel-framework, laravel-package
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (+1110.53%)
Mutual labels:  laravel-framework, laravel-package
Laravel Qrcode Ecommerce
This is a complete laravel project that handles qrcodes, payments, api/microservices, and ecommerce
Stars: ✭ 36 (+89.47%)
Mutual labels:  laravel-framework, laravel-package
Dropzone Laravel Image Upload
Laravel 5.2 and Dropzone.js auto image uploads with removal links
Stars: ✭ 92 (+384.21%)
Mutual labels:  laravel-framework, laravel-package
csv
No description or website provided.
Stars: ✭ 47 (+147.37%)
Mutual labels:  laravel-framework, laravel-package
Wagonwheel
Offer an online version of your Laravel emails to users.
Stars: ✭ 224 (+1078.95%)
Mutual labels:  laravel-framework, laravel-package
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+942.11%)
Mutual labels:  laravel-framework, laravel-package
Snooze
A package to simplify automating future notifications and reminders in Laravel
Stars: ✭ 515 (+2610.53%)
Mutual labels:  laravel-framework, laravel-package
Laravel User Activity
Monitor user activity easily!
Stars: ✭ 253 (+1231.58%)
Mutual labels:  laravel-framework, laravel-package
Laravel Code Generator
An intelligent code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages and/or form-requests! It is extremely flexible and customizable to cover many on the use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.
Stars: ✭ 485 (+2452.63%)
Mutual labels:  laravel-framework, laravel-package
Laravel Compass
A REST client inside your Laravel app
Stars: ✭ 1,002 (+5173.68%)
Mutual labels:  laravel-framework, laravel-package
Laravel Form Components
A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!
Stars: ✭ 295 (+1452.63%)
Mutual labels:  laravel-framework, laravel-package
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (+310.53%)
Mutual labels:  laravel-framework, laravel-package
email-checker
Provides email verification on the go.
Stars: ✭ 116 (+510.53%)
Mutual labels:  laravel-framework, laravel-package
Base62
PHP Base62 encoder and decoder for integers and big integers with Laravel 5 support.
Stars: ✭ 16 (-15.79%)
Mutual labels:  laravel-framework, laravel-package
Laravel Api Boilerplate
A Boilerplate Project For Laravel API's (NOT MAINTAINED)
Stars: ✭ 113 (+494.74%)
Mutual labels:  laravel-framework, jwt-auth
Laravel Gitscrum
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
Stars: ✭ 2,686 (+14036.84%)
Mutual labels:  laravel-framework, laravel-package

laravel-jwt-auto-installer

Latest Version forks stars license Total Downloads

A Laravel Library that let's you add tymon jwt auth library and all it's features with single command

Why this was required?

The people who uses tymon/jwt-auth knows that every time they installs package they need to manually create AuthController and then copy and paste the entire code their and same things for Model and Routes. So every time when you have to do this it takes some time and being a developer we want more easy and simple way of doing thing. so the i came up with this idea of creating this and hopefully it will help you and will make your work easy.

what this package will do?

The package will create the following things for you

  • installs tymon/jwt-auth for you
  • Will publish AuthController (with code) inside App\Http\Controllers
  • User.php (Model with all code including jwt functions)
  • Will publish Routes (will create all the routes for auth e.g(login, register, authenticated user detail, refresh token, logout) in api.php)
  • Will also publish the JWT_SECRET in your .env

Installation

Use the package manager composer to install laravel-jwt-auto-installer.

composer require salmanzafar/laravel-jwt-auto-installer

Enable the package (Optional)

This package implements Laravel auto-discovery feature. After you install it the package provider and facade are added automatically for laravel >= 5.5.

Configuration

Publish the service provider file

This step is required

php artisan vendor:publish --provider="Salman\AutoJWT\AutoJWTServiceProvider"

Usage

php artisan jwt:init

Controller Model and Routes and Jwt Secret published.Thanks

That's it now it'll publish every thing you want e.g Controller Model(with functions jwt) and api routes for JWT

AuthController.php:

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Symfony\Component\HttpFoundation\Response;

class AuthController extends Controller
{
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:api', ['except' => ['login','register']]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     * @throws \Illuminate\Validation\ValidationException
     */
    public function register(Request $request)
    {
        $this->validate($request, [
          "name" => "required|string|min:4",
          "email" => "required|email",
          "password" => "required|min:8|max:20|confirmed"
        ]);

        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password),
        ]);

        return response([
            'data' => 'Thank you.Your account has been created'
        ],Response::HTTP_CREATED);
    }

    /**
     * Get a JWT via given credentials.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function login()
    {
        $credentials = request(['email', 'password']);

        if (! $token = auth()->attempt($credentials)) {
            return response()->json(['error' => 'Unauthorized'], 401);
        }

        return $this->respondWithToken($token);
    }

    /**
     * Get the authenticated User.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function me()
    {
        return response()->json(auth()->user());
    }

    /**
     * Log the user out (Invalidate the token).
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function logout()
    {
        auth()->logout();

        return response()->json(['message' => 'Successfully logged out']);
    }

    /**
     * Refresh a token.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function refresh()
    {
        return $this->respondWithToken(auth()->refresh());
    }

    /**
     * Get the token array structure.
     *
     * @param  string $token
     *
     * @return \Illuminate\Http\JsonResponse
     */
    protected function respondWithToken($token)
    {
        return response()->json([
            'access_token' => $token,
            'token_type' => 'bearer',
            'expires_in' => auth()->factory()->getTTL() * 60
        ]);
    }
}

User.php

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

      /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = [
            'name', 'email', 'password',
        ];

        /**
         * The attributes that should be hidden for arrays.
         *
         * @var array
         */
        protected $hidden = [
            'password', 'remember_token',
        ];

        /**
         * The attributes that should be cast to native types.
         *
         * @var array
         */
        protected $casts = [
            'email_verified_at' => 'datetime',
        ];


    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
}

api.php

Route::group(['prefix' => 'user'], function () {
            Route::post('register', 'AuthController@register');
            Route::post('login',  'AuthController@login');
            Route::group(['middleware' => ['auth:api']], function () {
                Route::post('refresh', 'AuthController@refresh');
                Route::post('me', 'AuthController@me');
                Route::post('logout', 'AuthController@logout');
            });
});

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Tested on php 7.3 & 7.4 and laravel 6^

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].