Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/micro-php/plugin-oauth2-client
Micro Framework: OAuth2 client based on "league/oauth2-client"
https://github.com/micro-php/plugin-oauth2-client
Last synced: about 2 months ago
JSON representation
Micro Framework: OAuth2 client based on "league/oauth2-client"
- Host: GitHub
- URL: https://github.com/micro-php/plugin-oauth2-client
- Owner: Micro-PHP
- License: mit
- Created: 2022-12-25T00:29:16.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-06T20:51:58.000Z (6 months ago)
- Last Synced: 2024-11-09T07:20:35.957Z (2 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Micro Framework Oauth2 client plugin
Micro Framework: OAuth2 client based on "league/oauth2-client"
## InstallationInstall plugin with composer
```bash
$ composer require micro/plugin-oauth2-client
```And install a specific provider(s).
Available providers:
[micro/plugin-oauth2-client-keycloak]()Аnd then add plugin to the list of plugins (etc/plugins.php)
```php
$pluginsCommon = [
//....OTHER PLUGINS ....
Micro\Plugin\OAuth2\Client\OAuth2ClientPlugin::class,
Micro\Plugin\OAuth2\Client\Keycloak\OAuth2KeycloakProviderPlugin::class,
];```
Configure your oauth2 providersThe adapter configuration template usually looks like this `MICRO_OAUTH2__`
Default adapter name "default"
```dotenv
MICRO_OAUTH2_DEFAULT_TYPE=keycloak
MICRO_OAUTH2_DEFAULT_CLIENT_ID=
MICRO_OAUTH2_DEFAULT_CLIENT_SECRET=
MICRO_OAUTH2_DEFAULT_CLIENT_URL_AUTHORIZATION=
MICRO_OAUTH2_DEFAULT_CLIENT_URL_REDIRECT=
```## Usage/Examples
Index document
```php
use use Micro\Plugin\OAuth2\Client\Facade\Oauth2ClientFacadeInterface;
/** Unauthorized user */
$client = $container->get(Oauth2ClientFacadeInterface::class);
$provider = $client->getProvider('default');$provider->getAuthorizationUrl(); This method will return the full path to the server for user authorization.
/*** Response from the authorization server with a code */
$accessToken = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code'],
]);$owner = $provider->getResourceOwner($accessToken);
$id = $owner->getId();
$ownerData = $owner->toArray(); //Associated data with the user.```
## Support
For support, email [email protected].
## Authors
- [@stanislau_komar](https://www.github.com/asisyas)
## License
[MIT](LICENSE)