Download the PHP package beyondbluesky/oauth2-pkce-client without Composer
On this page you can find all versions of the php package beyondbluesky/oauth2-pkce-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beyondbluesky/oauth2-pkce-client
More information about beyondbluesky/oauth2-pkce-client
Files in beyondbluesky/oauth2-pkce-client
Package oauth2-pkce-client
Short Description OAuth2 Client implementation using PKCE
License CC-BY-NC-SA-4.0
Informations about the package oauth2-pkce-client
OAuth2 PKCE Enabled client
This Symfony bundle allows a Symfony4/5/6 installation authenticate it's users against an OAuth2 compliant server using the PKCE extension.
The PKCE extension RFC-7636 (https://tools.ietf.org/html/rfc7636) adds additional security to the OAuth2 protocol and it will be mandatory on future versions of OAuth2.
This implementation requires the generation of:
- An Authenticator
- A Controller to receive the response from the OAuth2 Server
- A table to store the session information (oauth2_session). The table is used to store the session information, including the challenge and verifier strings, used to secure the communication as part of the PKCE extension.
- The required config file where we'll store the client_id, oauth2 uris, etc.
- The modification of security.yml to include all the previous configuration
Following you'll find all the steps to configure it. Don't worry...
Installation
To install it you need to follow the following stemps:
-
Download the latest version of the bundle
- Configure the endpoints of your OAuth2 server with a file at config/packages named oauth2_pkce_client:
config/packages/oauth2_pkce_client.yaml:
- Create a Controller to receive the tokens, that has to match the redirect_uri path. Following we provide an example code for you to adapt:
src/Controller/OAuth2Controller.php:
- Create a user class. The minimum information should be the username. All other fields are optional and filled in the point 5 of this guide. In our case we'll create a Security\User inside the Entity folder.
If you are new to this, I highly recommend to use the command
And follow the questions asked, adding the username field and all the fields you need for your project. That will generate an ORM configured entity with all the information needed.
Once you have created your user, edit it and implement the UserInterface interface to tell Symfony your user entity is a Symfony User:
With the implementation of the UserInterface you'll have to add a few Symfony functions:
- Now we need a new Authenticator. Use to following code as a template. Take into consideration the getUser function, you'll have to fill your user object with the fields that you'll receive from your OAuth2 server. Yo can var_dump the oauthUser if you are not sure what you are receiving:
src/Security/OAuth2Authenticator.php:
-
Update your database schema: schema:update or doctrine:migrations, your choice.
- Configure the security.yaml to point to our new authenticator
On the providers section replace the in-memory line for:
config/packages/security.yaml:
And on firewalls > main refer to your new user provider and add our authenticator created at step 5:
- Enjoy your new OAuth2 authentication! For that go to your Symfony root on a browser and add a oauth2/login to the URL (if you didn't change the paths on the OAuth2Controller). Now you should see the login page of your OAuth2 server.
Have fun!
All versions of oauth2-pkce-client with dependencies
symfony/framework-bundle Version ^5.1|^5.2|^6.3
symfony/dependency-injection Version ^5.1|^5.2|^6.3
symfony/routing Version ^5.1|^5.2|^6.3
symfony/http-foundation Version ^5.1|^5.2|^6.3
beyondbluesky/lib-jwt Version 1.*