Search code examples
postmanslack

How can I get a response when calling Slack's oauth/authorize?


When I try to make the following call using postman I get no response: https://slack.com/oauth/authorize?client_id={{client id}}&scope=chat:write:bot

However, when I try it without the scope I do get a response, saying I need to add a scope.

I've put this call together according to the first step of https://api.slack.com/docs/oauth

I've tried using both GET and POST verbs and my header is empty.

What can I do to get a authorization token for Slack?


Solution

  • This is part of the OAuth flow/spec.

    What you need to do to is follow/perform the OAuth flow:

    1. Register your application with slack

    2. Provide a redirect_uri - this is the callback URI - this callback/handler will be called with the authenticationCode by the slack OAuth server.

      Only if the user authorizes your app, Slack will redirect back to your specified redirect_uri with a temporary code in a code GET parameter, as well as a state parameter if you provided one in the previous step.

      It's true that the redirect url is optional, but if left out, Slack will redirect users to the callback URL configured in your app's settings.

    3. the authenticationCode then needs to be changed in code to the accessToken. So if all is well and user gave its consent, you need to exchange the authorization code for an access token using the OAuth.access API method (method documentation), int the following URL and retrieve your accessToken.

      https://slack.com/api/oauth.access

    4. if you decide to use a bot user and your Slack app includes a bot user, you will get an additional node containing an access token to be specifically used for your bot user.