andalisolutions / oauth2-anaf
Anaf OAuth 2.0 support for the PHP League's OAuth 2.0 Client
v1.0.0
2024-01-28 22:05 UTC
Requires
- php: ^8.1.0
- league/oauth2-client: ^2.7
Requires (Dev)
- laravel/pint: ^1.2.0
- mockery/mockery: ^1.6
- pestphp/pest: ^2.0.0
- phpstan/phpstan: ^1.8.6
- symfony/var-dumper: ^6.2.0
This package is auto-updated.
Last update: 2025-01-29 13:58:25 UTC
README
ANAF Provider for OAuth 2.0 Client
This package provides ANAF OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
Installation
To install, use composer:
composer require andalisolutions/oauth2-anaf
Usage
Usage is the same as The League's OAuth client, using \Anaf\OAuth2\Client\Provider\AnafProvider
as the provider.
Authorization Code Flow
$provider = new Anaf\OAuth2\Client\Provider\AnafProvider( clientId: '{anaf-client-id}', clientSecret: '{anaf-client-secret}', redirectUrl: 'https://example.com/callback-url', ); // Redirect to the authorization URL $authorizationUrl = $provider->getAuthorizationUrl(); header('Location: ' . $authorizationUrl); // This part will be in your callback script if (isset($_GET['code'])) { try { $accessToken = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'], ]); // We have an access token, which we may use in authenticated // requests against the service provider's API. echo 'Access Token: ' . $accessToken->getToken() . "<br>"; echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "<br>"; echo 'Expired in: ' . $accessToken->getExpires() . "<br>"; echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>"; } catch (Exception $e) { // Handle errors, such as an invalid code } }
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.