Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 062dd54

Browse files
committed
🚿 allow custom scopes in examples
1 parent fd0d6ed commit 062dd54

23 files changed

+50
-26
lines changed

examples/get-token/Amazon.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$amazon = new Amazon($http, $storage, $options, $logger);
2627
$servicename = $amazon->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$amazon->getAuthURL());
31+
header('Location: '.$amazon->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/BattleNet.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$battlenet = new BattleNet($http, $storage, $options, $logger);
2627
$servicename = $battlenet->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$battlenet->getAuthURL());
31+
header('Location: '.$battlenet->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Deezer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$deezer = new Deezer($http, $storage, $options, $logger);
2627
$servicename = $deezer->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$deezer->getAuthURL());
31+
header('Location: '.$deezer->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/DeviantArt.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$deviantart = new DeviantArt($http, $storage, $options, $logger);
2627
$servicename = $deviantart->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$deviantart->getAuthURL());
31+
header('Location: '.$deviantart->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Discord.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$discord = new Discord($http, $storage, $options, $logger);
2627
$servicename = $discord->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$discord->getAuthURL());
31+
header('Location: '.$discord->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/GitHub.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$github = new GitHub($http, $storage, $options, $logger);
2627
$servicename = $github->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$github->getAuthURL());
31+
header('Location: '.$github->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Gitter.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$gitter = new Gitter($http, $storage, $options, $logger);
2627
$servicename = $gitter->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$gitter->getAuthURL());
31+
header('Location: '.$gitter->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Google.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$google = new Google($http, $storage, $options, $logger);
@@ -29,7 +30,7 @@
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
3031
$params = ['access_type' => 'online'];
3132

32-
header('Location: '.$google->getAuthURL($params));
33+
header('Location: '.$google->getAuthURL($params, $SCOPES));
3334
}
3435
// step 3: receive the access token
3536
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Instagram.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$instagram = new Instagram($http, $storage, $options, $logger);
2627
$servicename = $instagram->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$instagram->getAuthURL());
31+
header('Location: '.$instagram->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Mastodon.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
2323
* @var \chillerlan\DotEnv\DotEnv $env
24+
* @var array $SCOPES
2425
*/
2526

2627
// set the mastodon instance we're about to request data from
@@ -29,7 +30,7 @@
2930

3031
// step 2: redirect to the provider's login screen
3132
if(isset($_GET['login']) && $_GET['login'] === $servicename){
32-
header('Location: '.$mastodon->getAuthURL());
33+
header('Location: '.$mastodon->getAuthURL(null, $SCOPES));
3334
}
3435
// step 3: receive the access token
3536
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/MicrosoftGraph.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$msgraph = new MicrosoftGraph($http, $storage, $options, $logger);
2627
$servicename = $msgraph->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$msgraph->getAuthURL());
31+
header('Location: '.$msgraph->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/NPROne.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$npr = new NPROne($http, $storage, $options, $logger);
2627
$servicename = $npr->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$npr->getAuthURL());
31+
header('Location: '.$npr->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Patreon1.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$patreon1 = new Patreon1($http, $storage, $options, $logger);
2627
$servicename = $patreon1->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$patreon1->getAuthURL());
31+
header('Location: '.$patreon1->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Patreon2.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$patreon2 = new Patreon2($http, $storage, $options, $logger);
2627
$servicename = $patreon2->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$patreon2->getAuthURL());
31+
header('Location: '.$patreon2->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/PayPal.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$paypal = new PayPal($http, $storage, $options, $logger);
@@ -28,7 +29,7 @@
2829

2930
// step 2: redirect to the provider's login screen
3031
if(isset($_GET['login']) && $_GET['login'] === $servicename){
31-
header('Location: '.$paypal->getAuthURL(['flowEntry' => 'static', 'fullPage' => 'true']));
32+
header('Location: '.$paypal->getAuthURL(['flowEntry' => 'static', 'fullPage' => 'true'], $SCOPES));
3233
}
3334
// step 3: receive the access token
3435
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Slack.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$slack = new Slack($http, $storage, $options, $logger);
2627
$servicename = $slack->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$slack->getAuthURL());
31+
header('Location: '.$slack->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/SoundCloud.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$soundcloud = new SoundCloud($http, $storage, $options, $logger);
2627
$servicename = $soundcloud->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$soundcloud->getAuthURL());
31+
header('Location: '.$soundcloud->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code'])){ // soundcloud doesn't support <state>

examples/get-token/Spotify.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$spotify = new Spotify($http, $storage, $options, $logger);
2627
$servicename = $spotify->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$spotify->getAuthURL());
31+
header('Location: '.$spotify->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Stripe.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$stripe = new Stripe($http, $storage, $options, $logger);
2627
$servicename = $stripe->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$stripe->getAuthURL());
31+
header('Location: '.$stripe->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Twitch.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$twitch = new Twitch($http, $storage, $options, $logger);
2627
$servicename = $twitch->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$twitch->getAuthURL());
31+
header('Location: '.$twitch->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Vimeo.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$vimeo = new Vimeo($http, $storage, $options, $logger);
2627
$servicename = $vimeo->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$vimeo->getAuthURL());
31+
header('Location: '.$vimeo->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/get-token/Wordpress.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2121
* @var \chillerlan\Settings\SettingsContainerInterface $options
2222
* @var \Psr\Log\LoggerInterface $logger
23+
* @var array $SCOPES
2324
*/
2425

2526
$wordpress = new Wordpress($http, $storage, $options, $logger);
2627
$servicename = $wordpress->serviceName;
2728

2829
// step 2: redirect to the provider's login screen
2930
if(isset($_GET['login']) && $_GET['login'] === $servicename){
30-
header('Location: '.$wordpress->getAuthURL());
31+
header('Location: '.$wordpress->getAuthURL(null, $SCOPES));
3132
}
3233
// step 3: receive the access token
3334
elseif(isset($_GET['code']) && isset($_GET['state'])){

examples/provider-example-common.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
* @var string $ENVVAR - name prefix for the environment variable
3636
* @var string $CFGDIR - the directory where configuration is stored (.env, cacert, tokens)
3737
* @var string $LOGLEVEL - log level for the test logger, use 'none' to suppress logging
38+
* @var array $SCOPES - a set of scopes for the current provider (OAuth2 only)
3839
*/
39-
$ENVFILE = $ENVFILE ?? '.env';
40-
$ENVVAR = $ENVVAR ?? '';
41-
$CFGDIR = $CFGDIR ?? __DIR__.'/../config';
42-
$LOGLEVEL = $LOGLEVEL ?? 'info';
40+
$ENVFILE ??= '.env';
41+
$ENVVAR ??= '';
42+
$CFGDIR ??= __DIR__.'/../config';
43+
$LOGLEVEL ??= 'info';
44+
$SCOPES ??= null;
4345

4446
$env = (new DotEnv($CFGDIR, $ENVFILE, false))->load();
4547

0 commit comments

Comments
 (0)