Download the PHP package aikrof/jwt-auth without Composer

On this page you can find all versions of the php package aikrof/jwt-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package jwt-auth

Simple JSON Web Token Authentication

1. Instalation

composer require aikrof/jwt-auth

2. Add service provider

Add the service provider to the providers array in the config/app.php config file:

'providers' => [
    ...
    Aikrof\JwtAuth\Providers\JwtServiceProvider::class,
    ...
],

3. Publish the config file

php artisan vendor:publish --provider="Aikrof\JwtAuth\Providers\JwtServiceProvider"

This command will be create config/jwt.php file with basics configure.


4. Migrate table

Create table where will be stored invalid tokens.

php artisan migrate

5. Generate secret and refresh keys

php artisan create:secret

This command will create JWT_SECRET_KEY and JWT_REFRESH_KEY in your .env file.


6. Configure Auth guard

Inside the config/auth.php file change:

    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
    ...
    'guards' => [
        ...
        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
    ],

Set api guard as the default and add jwt driver to api guard


7. Update your User model

Add trait to your User model:
1)Implement the Aikrof\JwtAuth\JwtCreator
2)Then add trait use JwtCreator

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Aikrof\JwtAuth\JwtCreator;

class User extends Authenticatable
{
    use JwtCreator, Notifiable;

    ....
}

8. Usage

1)Set tokens time to live
1. Set token time to live

By default token time to live (ttl) is 1 week, you can change ttl in config/jwt.php file or when create new token:

Auth::user()->setTtl(2);

Example sets token time to live by 2 minutes.
setTtl() -takes parameter in minutes.

1. Set refresh token time to live

By default refresh token time to live is token ttl * 2, you can change refreshTtl in config/jwt.php file or when create new token:

Auth::user()->setRefreshTtl(4);

Example sets token time to live by 4 minutes.
setRefreshTtl() -takes parameter in minutes.


2)Create JWT token and refresh token
Auth::token();

Or with setTtl() or setRefreshTtl()

Auth::user()->setTtl(2)->setRefreshTtl()->token();

Will be returned array with this fields:

[
    'token' => '...',
    'refresh' => '...'
]

3)Get tokens time to live
1. To get token time to live in minutes
Auth::user()->getTtl();

To get token time to live in UNIX timestamp

Auth::user()->getExpTtl();
2. To get refresh token time to live in minutes
Auth::user()->getRefreshTtl();

To get refresh token time to live in UNIX timestamp

Auth::user()->getRefreshExpTtl();

4)Logout user

Log the user out - which will invalidate the current token and unset the authenticated user.

Auth::logout();

5)Refresh JWT tokens

Refresh a token, which invalidates the current one and returned new token and refresh token.

Auth::refresh();

If jwt token was invalid or have invalid data then will be returned null.


All versions of jwt-auth with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.8
illuminate/console Version ^5.8
illuminate/support Version ^5.8
illuminate/http Version ^5.8
illuminate/auth Version ^5.8
illuminate/contracts Version ^5.8
illuminate/database Version ^5.8
nesbot/carbon Version ^2.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aikrof/jwt-auth contains the following files

Loading the files please wait ....