Skip to content

This is a starter project for any PHP Symfony API platform project with user creation and authentication (jwt access and refresh tokens implementation)

Notifications You must be signed in to change notification settings

stefmedjo/api-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Platform starter

This is a starter for your API platform project.

Requirements

  • PHP 7.4
  • MySQL 5

Generate keys

Create a folder named jwt in config folder:

mkdir config/jwt

Generate a private key using openssl

openssl genrsa -out config/jwt/private.pem -aes256 4096

You will have to provide a pass phrase.

Next, you will generate the public key:

openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem

You will have to provide the same pass phrase.

Configuration

In the config/packages/lexik_jwt_authentication.yaml file, you have to add the token_ttl (An access token has a “time-to-live” (ttl), which is the maximum time that the access token will be valid for use within the application. 3600 seconds is 1 hour)

Add refresh token

composer require gesdinet/jwt-refresh-token-bundle

In the file config/routes.yaml, add :

gesdinet_jwt_refresh_token:
    path:       /token/refresh
    controller: gesdinet.jwtrefreshtoken::refresh

In the security, add this in the firewall section:

    refresh:
        pattern:  ^/token/refresh
        stateless: true
        anonymous: true

Create gesdinet_jwt_refresh_token.yaml in config/packages, and add :

  gesdinet_jwt_refresh_token:
      ttl: 2592000
      user_identity_field: email

About

This is a starter project for any PHP Symfony API platform project with user creation and authentication (jwt access and refresh tokens implementation)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published