1. Go to this page and download the library: Download maer/oauth2-simple-client 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/ */
maer / oauth2-simple-client example snippets
Usage
### The factory way
#### Config
Start by adding the configuration file. Let's use Google as example:
Maer\Oauth2Simple\Client\Factory::config('my-google', [
'clientId' => 'XXXXXXXX',
'clientSecret' => 'XXXXXXXX',
'redirectUri' => 'https://example.com/callback/',
'scopes' => ['email'],
'provider' => 'google',
'emailAllow' => ['[email protected]', '@example.com'], # Optional
'emailDeny' => ['[email protected]', '@evil.com'] # Optional
]);
The "provider" parameter can be any of the built in providers in "league/oauth2-client". You can head over to that repository to get more information. This package is using the latest 0.9.*-version.
It can also be the name of a custom provider, more about those, go to the "league/oauth2-client".
If it is a custom provider, enter the full namespace to that class, like: `"provider" : "Namespace\To\Provider\MyProvider"`
This will only save the configuration in the factory under the name "my-google". It will not make any instances or connect to anything so feel free to do this in your bootstrap or when ever. As long as it is before you try to get a connection.
#### Connect
Get a configured connection:
$provider = Maer\Oauth2Simple\Client\Factory::get('my-google');
Get the authorization URL:
<a href="<?= $provider->getAuthorizationUrl()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.