Slack Oauth与adam-paterson / oauth2-slack整合

问题描述 投票:0回答:2

我正在尝试使用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字段为空

将范围发送到服务器需要做什么?

php oauth slack-api slack
2个回答
1
投票

像这样在 $provider = new \AdamPaterson\OAuth2\Client\Provider\Slack([ 'clientId' => $slackid, 'clientSecret' => $slacksecret, 'redirectUri' => $returnURL, 'scope' => 'channels:write,groups:write,team:read' ]); 方法中添加范围

getAuthorizationUrl()

0
投票

在OAuth中使用 $authUrl = $provider->getAuthorizationUrl([ 'scope' => 'channels:write' ]); 中定义的范围,例如: 'scope'=>'users.profile:read'

© www.soinside.com 2019 - 2024. All rights reserved.