40use League\OAuth2\Client\Provider\Google;
42use Hayageek\OAuth2\Client\Provider\Yahoo;
44use Stevenmaguire\OAuth2\Client\Provider\Microsoft;
49<body>Select Provider:<br/>
50<a href=
'?provider=Google'>Google</a><br/>
51<a href=
'?provider=Yahoo'>Yahoo</a><br/>
52<a href=
'?provider=Microsoft'>Microsoft/Outlook/Hotmail/Live/Office365</a><br/>
59require
'vendor/autoload.php';
65if (array_key_exists(
'provider',
$_GET)) {
68} elseif (array_key_exists(
'provider',
$_SESSION)) {
71if (!in_array(
$providerName, [
'Google',
'Microsoft',
'Yahoo'])) {
72 exit(
'Only Google, Microsoft and Yahoo OAuth2 providers are currently supported in this script.');
77$clientId =
'RANDOMCHARS-----duv1n2.apps.googleusercontent.com';
88 'accessType' =>
'offline'
99 'https://mail.google.com/'
118 exit(
'Provider missing');
121if (!isset(
$_GET[
'code'])) {
125 header(
'Location: ' . $authUrl);
131 exit(
'Invalid state');
136 'authorization_code',
138 'code' =>
$_GET[
'code']
143 echo
'Refresh Token: ',
$token->getRefreshToken();
An exception for terminatinating execution or to throw for unit testing.
Get an OAuth2 token from an OAuth2 provider.
if(array_key_exists('provider', $_GET)) elseif(array_key_exists( 'provider', $_SESSION)) if(!in_array($providerName, ['Google', 'Microsoft', 'Yahoo'])) $clientId
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']