我是OAuth的新手,但是因为它看起来很有趣,所以我想看看它。我读过和看过一些教程,我了解基本知识。我下载了使用此客户端的BitBucket provider:https://github.com/stevenmaguire/oauth2-bitbucket:https://github.com/thephpleague/oauth2-client
我不明白的是:如何设置accessToken?当url中没有代码时,它重定向并将其添加到url中,那么我将得到accessToken和refreshToken,但是如何使用该accessToken呢?我尝试过一些东西,也是$provider->setAccessToken(),但是这个函数不存在。
希望有人能帮我。这可能很容易但我看不出来。
发布于 2016-12-28 13:28:31
您收到的访问令牌不需要使用任何方法显式设置。有一些方法可以获取用户的详细信息,其中应该将该访问令牌作为参数传递。正如您在文档中所提供的那样:
// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
// Optional: Now you have a token you can look up a users profile data
try {
// We got an access token, let's now get the user's details
$user = $provider->getResourceOwner($token);
// Use these details to create a new profile
printf('Hello %s!', $user->getId());
} catch (Exception $e) {
// Failed to get user details
exit('Oh dear...');在这里,应该给getResourceOwner方法令牌,并返回与$token相关的用户详细信息。
https://stackoverflow.com/questions/41358213
复制相似问题