{"id":21038210,"url":"https://github.com/jglchen/laravel-auth-jwt","last_synced_at":"2026-04-20T10:32:43.105Z","repository":{"id":196349411,"uuid":"683198373","full_name":"jglchen/laravel-auth-jwt","owner":"jglchen","description":"Laravel JWT API Authentication","archived":false,"fork":false,"pushed_at":"2023-09-24T09:20:57.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-02T08:10:54.660Z","etag":null,"topics":["docker","jwt-authentication","jwt-token","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jglchen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-25T20:46:51.000Z","updated_at":"2023-08-25T21:51:22.000Z","dependencies_parsed_at":"2023-09-24T17:45:20.087Z","dependency_job_id":null,"html_url":"https://github.com/jglchen/laravel-auth-jwt","commit_stats":null,"previous_names":["jglchen/laravel-auth-jwt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jglchen/laravel-auth-jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jglchen%2Flaravel-auth-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jglchen%2Flaravel-auth-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jglchen%2Flaravel-auth-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jglchen%2Flaravel-auth-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jglchen","download_url":"https://codeload.github.com/jglchen/laravel-auth-jwt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jglchen%2Flaravel-auth-jwt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32043030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","jwt-authentication","jwt-token","laravel","php"],"created_at":"2024-11-19T13:30:04.791Z","updated_at":"2026-04-20T10:32:43.089Z","avatar_url":"https://github.com/jglchen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003ca href=\"https://laravel.com\" target=\"_blank\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg\" width=\"400\" alt=\"Laravel Logo\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/laravel/framework/actions\"\u003e\u003cimg src=\"https://github.com/laravel/framework/workflows/tests/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/laravel/framework\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/laravel/framework\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/laravel/framework\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/laravel/framework\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/laravel/framework\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/laravel/framework\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Laravel JWT API Authentication\n\nThere are different types of API authentication systems available in the Laravel application, like Laravel passport, Laravel sanctum and of course, we can also use JWT authentication. In this JSON Web Token Authentication for Laravel application, we will use JWT to create this API authentication in Laravel. **The php-open-source-saver/jwt-auth** package is used in this Laravel JWT authentication.\n\n## Installation\n\n### Install Laravel\n\nFirst, we need to get a fresh Laravel application using the below command.\n\n```bash\n# Create the Laravel application...\ncomposer create-project laravel/laravel laravel-auth-jwt\n\n```\n\n### Connect Database\n\nWe are going to use the SQLITE database for this jwt auth Laravel. So connect the database by updating .env like this:\n\n```bash\n# .env...\nDB_CONNECTION=sqlite\n\n```\nNow run the following command to migrate the database.\n```bash\n# migrate the database...\nphp artisan migrate\n\n```\n\n### Install JWT\n```bash\n# install php-open-source-saver/jwt-auth package...\ncomposer require php-open-source-saver/jwt-auth\n\n# publish the configuration file by running this command...\nphp artisan vendor:publish --provider=\"PHPOpenSourceSaver\\JWTAuth\\Providers\\LaravelServiceProvider\"\n\n# generate JWT secret key...\nphp artisan jwt:secret\n```\n\n### Configure API\n```bash\n# update config/auth.php\n\u003c?php\n\nreturn [\n\n    /*\n    |--------------------------------------------------------------------------\n    | Authentication Defaults\n    |--------------------------------------------------------------------------\n    |\n    | This option controls the default authentication \"guard\" and password\n    | reset options for your application. You may change these defaults\n    | as required, but they're a perfect start for most applications.\n    |\n    */\n\n    'defaults' =\u003e [\n        'guard' =\u003e 'api',\n        'passwords' =\u003e 'users',\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Authentication Guards\n    |--------------------------------------------------------------------------\n    |\n    | Next, you may define every authentication guard for your application.\n    | Of course, a great default configuration has been defined for you\n    | here which uses session storage and the Eloquent user provider.\n    |\n    | All authentication drivers have a user provider. This defines how the\n    | users are actually retrieved out of your database or other storage\n    | mechanisms used by this application to persist your user's data.\n    |\n    | Supported: \"session\"\n    |\n    */\n\n    'guards' =\u003e [\n        'web' =\u003e [\n            'driver' =\u003e 'session',\n            'provider' =\u003e 'users',\n        ],\n\n        'api' =\u003e [\n            'driver' =\u003e 'jwt',\n            'provider' =\u003e 'users',\n        ],\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | User Providers\n    |--------------------------------------------------------------------------\n    |\n    | All authentication drivers have a user provider. This defines how the\n    | users are actually retrieved out of your database or other storage\n    | mechanisms used by this application to persist your user's data.\n    |\n    | If you have multiple user tables or models you may configure multiple\n    | sources which represent each model / table. These sources may then\n    | be assigned to any extra authentication guards you have defined.\n    |\n    | Supported: \"database\", \"eloquent\"\n    |\n    */\n\n    'providers' =\u003e [\n        'users' =\u003e [\n            'driver' =\u003e 'eloquent',\n            'model' =\u003e App\\Models\\User::class,\n        ],\n\n        // 'users' =\u003e [\n        //     'driver' =\u003e 'database',\n        //     'table' =\u003e 'users',\n        // ],\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Resetting Passwords\n    |--------------------------------------------------------------------------\n    |\n    | You may specify multiple password reset configurations if you have more\n    | than one user table or model in the application and you want to have\n    | separate password reset settings based on the specific user types.\n    |\n    | The expiry time is the number of minutes that each reset token will be\n    | considered valid. This security feature keeps tokens short-lived so\n    | they have less time to be guessed. You may change this as needed.\n    |\n    | The throttle setting is the number of seconds a user must wait before\n    | generating more password reset tokens. This prevents the user from\n    | quickly generating a very large amount of password reset tokens.\n    |\n    */\n\n    'passwords' =\u003e [\n        'users' =\u003e [\n            'provider' =\u003e 'users',\n            'table' =\u003e 'password_reset_tokens',\n            'expire' =\u003e 60,\n            'throttle' =\u003e 60,\n        ],\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Password Confirmation Timeout\n    |--------------------------------------------------------------------------\n    |\n    | Here you may define the amount of seconds before a password confirmation\n    | times out and the user is prompted to re-enter their password via the\n    | confirmation screen. By default, the timeout lasts for three hours.\n    |\n    */\n\n    'password_timeout' =\u003e 10800,\n\n];\n\n```\n\n### Update User Model\n```bash\n# update app\\Models\\User.php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Laravel\\Sanctum\\HasApiTokens;\nuse Illuminate\\Notifications\\Notifiable;\nuse Illuminate\\Contracts\\Auth\\MustVerifyEmail;\nuse PHPOpenSourceSaver\\JWTAuth\\Contracts\\JWTSubject;\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable implements JWTSubject\n{\n    use HasApiTokens, HasFactory, Notifiable;\n\n    /**\n     * The attributes that are mass assignable.\n     *\n     * @var array\u003cint, string\u003e\n     */\n    protected $fillable = [\n        'name',\n        'email',\n        'password',\n    ];\n\n    /**\n     * The attributes that should be hidden for serialization.\n     *\n     * @var array\u003cint, string\u003e\n     */\n    protected $hidden = [\n        'password',\n        'remember_token',\n    ];\n\n    /**\n     * The attributes that should be cast.\n     *\n     * @var array\u003cstring, string\u003e\n     */\n    protected $casts = [\n        'email_verified_at' =\u003e 'datetime',\n    ];\n\n    /**\n     * Get the identifier that will be stored in the subject claim of the JWT.\n     *\n     * @return mixed\n     */\n    public function getJWTIdentifier()\n    {\n        return $this-\u003egetKey();\n    }\n\n    /**\n     * Return a key value array, containing any custom claims to be added to the JWT.\n     *\n     * @return array\n     */\n    public function getJWTCustomClaims()\n    {\n        return [];\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjglchen%2Flaravel-auth-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjglchen%2Flaravel-auth-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjglchen%2Flaravel-auth-jwt/lists"}