Download the PHP package adexos/m2-oauth2-league-bridge without Composer
On this page you can find all versions of the php package adexos/m2-oauth2-league-bridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download adexos/m2-oauth2-league-bridge
More information about adexos/m2-oauth2-league-bridge
Files in adexos/m2-oauth2-league-bridge
Package m2-oauth2-league-bridge
Short Description Oauth2 League Magento2 bridge
License
Informations about the package m2-oauth2-league-bridge
Adexos_Oauth2LeagueBridge
This module is intended to be a bridge client connection from OAuth 2 implementation for Magento 2.
Installation
You can install it by typing : composer require adexos/m2-oauth2-league-bridge
How to use ?
Create your own client extending the bridge one :
This class can be empty, it should only be created for the purpose of the di.xml
.
Then you can add your own configuration in the di.xml
:
The paths refer to your configuration. It's up to you to create your own system.xml
depending on the path you give.
Optional : You can set the backend_model entry in your config.xml
and system.xml
as Magento\Config\Model\Config\Backend\Encrypted
if you want to store your client secret in an encrypted way.
Example :
Here is a template as an example :
Please do not forget to create a config.xml
as well.
Finally, you can use it this way :
Of course you need to update the grant_type
and the options depending on your needs.
The identifier set as a second parameter will be used to persist the token somewhere based on your configuration.
If you now want to retrieve your token and update it with the refresh token if it exists, you can simply call :
Cache systems
There is two major cache systems used in this module to store your OAuth tokens :
- Session cache
- Magento native cache that drives file, Redis and database cache
Session cache
This cache is especially useful to use with Identity tokens (login) that must be stored within the customer session data, here is how you can implement it :
Classic cache
It uses Magento native system, so you can use any cache that Magento supports : file, Redis or database.
This cache is more useful when you don't need to store the token for the current session but in a more global context such as a Management token.
Here is how you can implement it :
Please note that the cacheIdentifier
will be used in the env.php
file to determine how you are storing your tokens :
Database
env.php
Redis
env.php
/!\ Please use a specific database to the cache, do not use the same database as the session.
File
env.php
Cache lifetime
If you need to add a specific lifetime for the cache which is 1 hour by default, you can override in your di.xml
the specificLifetime
property :
Tags
Cache is regrouped by tags. You may want to specify tags to clean specific global area of the cache you created.
In the default configuration, the tag is : adx_oauth2_league_bridge
You can override it by updating your di.xml
through the property tags
:
You can add many tags you want.
Decoding the token
You can decode the token after you fetched it, it will also do the verification with the public key to ensure the integrity of the received token :
The jwtDecoder
class is Adexos\Oauth2LeagueBridge\Decoder\JwtDecoder
As a second parameter of the decode
method, you must pass a DTO
implementing Adexos\Oauth2LeagueBridge\Decoder\Model\JwtResultInterface
which is the content representation of the
token. After that, you can manipulate the token result through an object and do whatever you want.
Alternative option provider (HttpBasicAuth/PostAuth)
The default option provider for the credentials concerning the access token is the PostAuthOptionProvider
.
However, there are some systems when you need to instead use a HttpBasicAuthOptionProvider
or even a custom one.
You simply need to add it in the di.xml
of your client :
If you need to implement your own auth provider, simply create a class implementing League\OAuth2\Client\OptionProvider\OptionProviderInterface
.
All versions of m2-oauth2-league-bridge with dependencies
league/oauth2-client Version ^2.6
firebase/php-jwt Version ^6.0
symfony/serializer Version >=4.4
symfony/property-access Version >=4.4