slack-ruby / slack-ruby-client

A Ruby and command-line client for the Slack Web, Real Time Messaging and Event APIs.
MIT License
1.21k stars 214 forks source link

oauth_access returning not_allowed_token_type #333

Closed AhmedSedek closed 3 years ago

AhmedSedek commented 4 years ago

I'm trying to create an oauth_access request as follows:

@client = Slack::Web::Client.new
@auth_params = @client.oauth_access({
  client_id: <client_id>,
  client_secret: <client_secret>,
  code: params[:code]
})

The client_id and client_secret are copied from https://api.slack.com/apps/<app_id>/general#App Credentials The code is returned from an oauth/authorize request https://slack.com/oauth/authorize?scope=identity.basic&client_id=<client_id>

Would this be a bug because on the oauth_access documentation, there are no such not_allowed_token_type error.?

The error trace:

23:43:11 web.1    | /home/blink22/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.14.4/lib/slack/web/faraday/response/raise_error.rb:11:in `on_complete': not_allowed_token_type (Slack::Web::Api::Errors::SlackError)
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/response.rb:9:in `block in call'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/response.rb:61:in `on_complete'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/response.rb:8:in `call'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/response.rb:8:in `call'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb:15:in `call'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/request/multipart.rb:15:in `call'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/rack_builder.rb:143:in `build_response'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/connection.rb:387:in `run_request'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/faraday-0.15.4/lib/faraday/connection.rb:175:in `post'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.14.4/lib/slack/web/faraday/request.rb:25:in `request'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.14.4/lib/slack/web/faraday/request.rb:10:in `post'
23:43:11 web.1    |     from /home/blink22/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.14.4/lib/slack/web/api/endpoints/oauth.rb:27:in `oauth_access'
...

UPDATE: I tried creating a post request manually using postman to https://slack.com/api/oauth.access?code=<code>&client_id=<client_id>&client_secret=<client_secret>, and I got a correct response as expected.

dblock commented 4 years ago

The oauth_access method in the client doesn't do anything special. I don't think what you're calling in postman is identical, or it would work. But This seems similar to https://github.com/slackapi/python-slackclient/issues/586, which says granular scopes, such as identity.basic, aren't allowed for RTM apps. Is that it?

crazyoptimist commented 4 years ago

I suspect your client credentials are from a default slack app @AhmedSedek . oauth_access doesn't work with default slack apps. It works with legacy slack apps. You should try to use oauth_v2_access. Check this PR.


Or you can still create a legacy slack app at https://api.slack.com/apps?new_classic_app=1

dblock commented 3 years ago

Closing this, please reopen if the problem persists @AhmedSedek