Download the PHP package proprietes-privees/jwt-refresh-token-bundle without Composer

On this page you can find all versions of the php package proprietes-privees/jwt-refresh-token-bundle. 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-refresh-token-bundle

JWTRefreshTokenBundle

Scrutinizer Code Quality Build Status Code Coverage Latest Stable Version Total Downloads License StyleCI

The purpose of this bundle is manage refresh tokens with JWT (Json Web Tokens) in an easy way. This bundles uses LexikJWTAuthenticationBundle. Supports Doctrine ORM/ODM.

Prerequisites

This bundle requires Symfony 3.4+, 4.0+ or 5.0+.

If you want to use this bundle with previous Symfony versions, please use 0.2.x releases.

Protip: Though the bundle doesn't enforce you to do so, it is highly recommended to use HTTPS.

Installation

Step 1: Download the Bundle

It's important you manually require either Doctrine's ORM or MongoDB ODM as well, these packages are not required automatically now as you can choose between them. Failing to do so may trigger errors on installation

With Doctrine's ORM

With Doctrine's MongoDB ODM

or edit composer.json:

// ...
"gesdinet/jwt-refresh-token-bundle": "~0.1",
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
"doctrine/mongodb-odm-bundle": "^3.4"
// ...

Step 2: Enable the Bundle

Symfony 3 Version:
Register bundle into app/AppKernel.php:

Symfony 4 Version:
Register bundle into config/bundles.php (Flex did it automatically):

Step 3: Configure your own routing to refresh token

Open your main routing configuration file and copy the following four lines at the very beginning of it.

Symfony 3 Version:

Symfony 4 Version:

Step 4: Allow anonymous access to refresh token

Add next lines on security.yml file:

Step 5: Update your schema

With the next command you will create a new table to handle your refresh tokens

Symfony 3 Version:

Symfony 4 Version:

USAGE

The configurations can be put in:

Symfony 3 Version: app/config
Symfony 4 Version: config/packages/gesdinet_jwt_refresh_token.yaml

Config TTL

You can define Refresh Token TTL. Default value is 1 month. You can change this value adding this line to your config:

Config User identity field

You can change user identity field. Make sure that your model user has getter for this field. Default value is username. You can change this value by adding this line to your config:

Config TTL update

You can expand Refresh Token TTL on refresh. Default value is false. You can change this value adding this line to your config:

This will reset the token TTL each time you ask a refresh.

Config Firewall Name

You can define Firewall name. Default value is api. You can change this value adding this line to your config:

Config Refresh token parameter Name

You can define refresh token parameter name. Default value is refresh_token. You can change this value adding this line to your config file:

Config UserProvider

You can define your own UserProvider. By default we use our custom UserProvider. You can change this value by adding this line to your config:

For example, if you are using FOSUserBundle, user_provider_service_id must be set to fos_user.user_provider.username_email.

For Doctrine ORM UserProvider, user_provider_service_id must be set to security.user.provider.concrete.<your_user_provider_name_in_security_yaml>. For example, in your app/config/security.yml or config/packages/security.yaml:

then your user_provider_service_id is security.user.provider.concrete.app_user_provider.

Select Manager Type

By default manager type is set to use Doctrine's ORM, if you want to use Doctrine's MongoDB ODM you have to change this value:

Config UserChecker

You can define your own UserChecker. By default the Symfony UserChecker will be used. You can change this value by adding this line to your config:

You will probably want to use a custom UserProvider along with your UserChecker to ensure that the checker recieves the right type of user.

Config Single Use

You can configure the refresh token so it can only be consumed once. If set to true and the refresh token is consumed, a new refresh token will be provided.

To enable this behavior add this line to your config:

Config refresh token in cookie

By default, refresh token is returned as JSON response. You can configure to retrieve it in a cookie. Cookie is then extracted from request automatically.

Here are default values.

Use another entity for refresh tokens

You can define your own refresh token class on your project.

When using default ORM create the entity class extending Gesdinet\JWTRefreshTokenBundle\Entity\AbstractRefreshToken in your own bundle:

When using MongoBD ODM create the document class extending Gesdinet\JWTRefreshTokenBundle\Document\AbstractRefreshToken in you own bundle:

Then declare this class adding this line to your config.yml file:

Use another object manager

You can tell JWTRefreshTokenBundle to use another object manager than default one (if using ORM it is doctrine.orm.entity_manager, when using MongoDB ODM it is doctrine_mongodb.odm.document_manager).

Just add this line to your config.yml file:

Generating Tokens

When you authenticate through /api/login_check with user/password credentials, LexikJWTAuthenticationBundle now returns a JWT Token and a Refresh Token data.

This refresh token is persisted in RefreshToken entity. After that, when your JWT valid token expires, if you want to get a new one you can proceed in two ways:

Note that when a refresh token is consumed and the config option single_use is set to true the token will no longer be valid.

This call returns a new valid JWT token renewing valid datetime of your refresh token.

Useful Commands

We give you two commands to manage tokens.

Revoke all invalid tokens

If you want to revoke all invalid (datetime expired) refresh tokens you can execute:

Symfony 3 Version:

Symfony 4 Version:

Optional argument is datetime, it deletes all tokens smaller than this datetime:

Symfony 3 Version:

Symfony 4 Version:

We recommend to execute this command with a cronjob to remove invalid refresh tokens every certain time.

Revoke a token

If you want to revoke a single token you can use this:

Symfony 3 Version:

Symfony 4 Version:

Events

If you want to do something when token is refreshed you can listen for gesdinet.refresh_token event.

For example:


All versions of jwt-refresh-token-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^5.5.9|>=7.0.8
symfony/framework-bundle Version ~3.4|~4.0|~5.0
symfony/validator Version ~3.4|~4.0|~5.0
lexik/jwt-authentication-bundle Version ^1.1|^2.0@dev
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 proprietes-privees/jwt-refresh-token-bundle contains the following files

Loading the files please wait ....