PHP code example of adexos / m2-oauth2-league-bridge
1. Go to this page and download the library: Download adexos/m2-oauth2-league-bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adexos / m2-oauth2-league-bridge example snippets
declare(strict_types=1);
namespace Adexos\MyIdentityOauthModule\Client;
use Adexos\Oauth2LeagueBridge\Client\OauthClientFactory;
class MyOauthIdentity extends OauthClientFactory
{
}
declare(strict_types=1);
namespace Adexos\MyIdentityOauthModule\Http\Token;
use Adexos\MyIdentityOauthModule\Client\MyOauthIdentity;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Magento\Framework\Exception\LocalizedException;
class IdentityTokenStrategy
{
private MyOauthIdentity $myOauthIdentity;
public function __construct(MyOauthIdentity $myOauthIdentity)
{
$this->myOauthIdentity = $myOauthIdentity;
}
/**
* @throws LocalizedException
* @throws IdentityProviderException
*/
public function find(): ?string
{
$accessToken = $this->myOauthIdentity->getAccessTokenWithPersistence(
new Password(),
'custom_identifier'
['username' => 'a', 'password' => 'b', 'scope' => 'custom_scopes']
);
if ($accessToken === null) {
return null;
}
return $accessToken->getToken();
}
}