我正在尝试使用Admin-paterson oauth库来连接到slack
(Qazxswpoi)
当我运行示例代码时:
https://github.com/adam-paterson/oauth2-slack
我从松弛中得到一个错误说:
include("slack-vendor/autoload.php");
include("slacker/src/Provider/Slack.php");
$provider = new \AdamPaterson\OAuth2\Client\Provider\Slack([
'clientId' => $$slackid,
'clientSecret' => $slacksecret,
'redirectUri' => $returnURL,
]);
if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl();
$_SESSION['oauth2state'] = $provider->getState();
header('Location: '.$authUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
// 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
$team = $provider->getResourceOwner($token);
// Use these details to create a new profile
printf('Hello %s!', $team->getName());
} catch (Exception $e) {
// Failed to get user details
exit('Oh dear...');
}
// Use this to interact with an API on the users behalf
echo $token->getToken();
}
我尝试在调用中添加“范围”,如下所示:
Invalid permissions requested
Requested scopes cannot be blank
但它仍然返回相同的错误。
当我查看url时,scope字段为空
将范围发送到服务器需要做什么?
像这样在 $provider = new \AdamPaterson\OAuth2\Client\Provider\Slack([
'clientId' => $slackid,
'clientSecret' => $slacksecret,
'redirectUri' => $returnURL,
'scope' => 'channels:write,groups:write,team:read'
]);
方法中添加范围
getAuthorizationUrl()
在OAuth中使用 $authUrl = $provider->getAuthorizationUrl([
'scope' => 'channels:write'
]);
中定义的范围,例如: 'scope'=>'users.profile:read'