Skip to content

Commit d61fb64

Browse files
committed
:octocat: oauth-flow examples: call me() only if UserInfo is implemented
1 parent 3394180 commit d61fb64

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

examples/get-token/_flow-oauth1.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
declare(strict_types=1);
1111

12+
use chillerlan\OAuth\Core\UserInfo;
13+
1214
/**
1315
* @var \chillerlan\OAuth\Core\OAuth1Interface $provider
1416
* @var \OAuthExampleProviderFactory $factory
@@ -36,10 +38,13 @@
3638
// use the file storage from now on
3739
$provider->setStorage($factory->getFileStorage());
3840

39-
$me = print_r($provider->me(), true);
41+
if($provider instanceof UserInfo){
42+
printf('<pre>%s</pre>', print_r($provider->me(), true));
43+
}
44+
4045
$tokenJSON = $provider->getAccessTokenFromStorage()->toJSON();
4146

42-
printf('<pre>%s</pre><textarea cols="120" rows="5" onclick="this.select();">%s</textarea>', $me, $tokenJSON);
47+
printf('<textarea cols="120" rows="5" onclick="this.select();">%s</textarea>', $tokenJSON);
4348
}
4449
// step 1 (optional): display a login link
4550
else{

examples/get-token/_flow-oauth2.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
declare(strict_types=1);
1111

12-
use chillerlan\OAuth\Core\CSRFToken;
12+
use chillerlan\OAuth\Core\{CSRFToken, UserInfo};
1313

1414
/**
1515
* @var \chillerlan\OAuth\Core\OAuth2Interface $provider
@@ -45,10 +45,13 @@
4545
// use the file storage from now on
4646
$provider->setStorage($factory->getFileStorage());
4747

48-
$me = print_r($provider->me(), true);
48+
if($provider instanceof UserInfo){
49+
printf('<pre>%s</pre>', print_r($provider->me(), true));
50+
}
51+
4952
$tokenJSON = $provider->getAccessTokenFromStorage()->toJSON();
5053

51-
printf('<pre>%s</pre><textarea cols="120" rows="5" onclick="this.select();">%s</textarea>', $me, $tokenJSON);
54+
printf('<textarea cols="120" rows="5" onclick="this.select();">%s</textarea>', $tokenJSON);
5255
}
5356
// step 1 (optional): display a login link
5457
else{

0 commit comments

Comments
 (0)