Download the PHP package maer/oauth2-simple-client without Composer
On this page you can find all versions of the php package maer/oauth2-simple-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maer/oauth2-simple-client
More information about maer/oauth2-simple-client
Files in maer/oauth2-simple-client
Package oauth2-simple-client
Short Description Wrapper for league/oauth2-client with a simplified API and possibility to allow/deny e-mail addresses/domains
License MIT
Informations about the package oauth2-simple-client
Oauth2 Simple Client
Wrapper for league/oauth2-client with a simplified API and possibility to black/whitelist e-mail addresses/domains.
It is framework agnostic so you can just plug and play.
Install
You need composer to make this work, since this package is dependent on league/oauth2-client. I guess you could install that by hand as well, but since that package is dependent on other packages, you're setting yourself up for failure. ;-)
Add the package:
composer require maer/oauth2-simple-client 0.1.*
Make sure to include the composer-generated autoloader:
">Log in</a>
On the callback page example.com/callback/
:
$user = $provider->authorize();
If the user was successfully autorized, you will get a user object back, otherwise it will return "false". Then you can check why by looking at the error message:
# For a human readable message
$errorMessage = $provider->getError();
# For an error code (check the constants in `Maer\Oauth2Simple\Client\Client`)
$errorCode = $provider->getErrorCode();
If you need the token:
$token = $provider->getToken();
If you want to do something that league/oauth2-client supports but isn't added to this wrapper, you can get the original provider:
$leaguesProvider = $provider->getProvider();
The manual way
$provider = new Maer\Oauth2Simple\Client\Client([
'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
]);
Now it's up to you to save the $provider
instance. Otherwise it's just like above.
E-mail allow/deny config
Maby we should talk about the allow- and deny lists. It is basically the reason I made this wrapper. :) With this you can decide who is or isn't allowed to authenticate/use your app depending on their e-mail address. This does require the e-mail to be returned from the provider so make sure you add the "email" in the scope. I will add the possibility to use oauthId's and other paramaeters, but started with e-mail since that was what I needed when I built this.
The emailAllow and emailDeny:
'emailAllow' => ['[email protected]', '@example.com']
This will only allow the user with the e-mail address [email protected]
or any user having an e-mail address on the @example.com
domain. If this array is empty, or not provided at all, it will be counted as everyone is allowed.
'emailDeny' => ['[email protected]', '@evil.com']
This will deny the user with the e-mail [email protected]
even if the domain @example.com
is allowed. No user from @evil.com
is allowed at all. This is kind of a bad example, since @evil.com would have been denied anyway, since we have an allow-list. Denying a domain only makes sence if you don't have an allow list (which as I stated previously is regarded as everyone is allowed).