slackapi / python-slack-sdk

Slack Developer Kit for Python
https://tools.slack.dev/python-slack-sdk/
MIT License
3.86k stars 833 forks source link

"API Token" in documentation too vague #320

Closed charlesreid1 closed 6 years ago

charlesreid1 commented 6 years ago

Description

A better variable name than "SLACK_API_TOKEN" should be used. This vague language is common to auth system documentation and makes it confusing and hard to understand. "API token" is too vague. Is that the BOT_TOKEN discussed here? The client ID/secret token? The consumer API token? A temporary access token that gives an application full permissions for my account, like Github provides, that I somehow generate...?

This tokens and authentication page mentions that you use test tokens in place of the API tokens. It then goes on to say, "Tester tokens are not intended to replace OAuth 2.0 tokens. Once your app is ready for users, replace this token with a proper OAuth token implementation." So, is the SLACK_API_TOKEN an OAuth token? Why would there only be one token, when OAuth gives you two (client ID and client secret)? Or is the test token something different from the API token?

I have a high level understanding of how OAuth works and have used it before, but I have no clue what Slack wants me to do because the terminology used in the documentation is not consistent.

Please tie this documentation to what a Slack user actually sees in their control panel, and where in in the control panel the Slack user can find these details.

What type of issue is this? (place an x in one of the [ ])

Requirements (place an x in each of the [ ])


Bug Report

(documentation fix)

charlesreid1 commented 6 years ago

This link (Create and regenerate API tokens) also mentions:

😕

charlesreid1 commented 6 years ago

This SO post mentions a user access token and a bot token, both resulting from the OAuth process. I'm guessing this bot API token is the one you really want, although this is not in any way made clear. The documentation gives fragments of a Flask app to run the OAuth process, but nothing complete. Is this provided as a single downloadable script in a repository somewhere?

I also don't see a way to change the callback URL of an app that's already been created anywhere in the documentation (or in the app settings, for that matter).

Overall, this documentation is throroughly bewildering. OAuth is a confusing process to begin with; this documentation makes it impossible to get up and running without investing several hours. Huge headache, especially compared to how easy it is to get rolling with Twitter and Github OAuth steps and APIs.

aoberoi commented 6 years ago

@charlesreid1 i can empathize with some of the confusion you are having, and i'm making notes and delivering this feedback to the rest of the team responsible for documentation. thank you for your candor.

the bottom line: any of the tokens you mentioned in this comment are valid to use for SLACK_API_TOKEN. its actually generic on purpose, although that purpose is not clear and i'm sorry about that.

i'll spare you the history lesson, but as you can probably imagine, the Slack API wasn't born in a day, and over time we invented different types of authentication tokens for using the API. all of them are still valid for authenticating against the API, so any of them can be used with this library.

now, depending on what you are trying to specifically build utilizing this library, one token type might be more correct than others.


you didn't mention this, but you might also see "Verification Token". this token is meant for your app to be able to authenticate Slack (rather than Slack to authenticate your app). with some features (slash commands, interactive messages, events API), Slack is the one sending you the request. in those cases, you want to make sure its actually Slack that sent the request, so you check to make sure the verification token matches what it says in your app management page.

lastly, the client id and client secret are only used in the OAuth process to exchange a authorization code (grant) for an access token. this is the request to oauth.access. these are constant identifiers for your app across all workspaces where the app is installed, but never used for authentication using the APIs.

pykenny commented 1 year ago

For anyone who run into this article while stretching head on reading article like this: https://api.slack.com/apis/connections/socket#sdks

image

(Solved, see below) (Can anyone explain, why there are two tokens used in the code, when there's only one app token is mentioned and set up in previous context? If an app token is combination of user token and bot token, as the above comment says, then why do we need another bot token (apply bot token to original app + apply app token to socket adapter) in this example?)

image
image

Update: Just saw the description of app token:

Special tokens used with specific APIs...

Now I think the difference between xoxa and xapp is that scopes granted to xapp is more restricted, so in the Socket Mode case, you'll still need a bot token to enable features like posting or reading channel history.

pykenny commented 1 year ago

Another perplexing part in the documentation is that now Slack offers signing secrets and claims to replace application tokens discussed in this thread with the new mechanism, while the other tutorials are still using the "old verification token"s to enable bots and applications.

~So what should I do now? Bolt's documentation keeps telling me to use the "to be deprecated" way for authentication! 🤷‍♂️~ (Update: Bolt's documentation covers signed secret setup in their tutorial)

So like the Socket Mode example above, the code may suffice before signing secrets get introduced, but it should be updated under current status. (Another example that possibly derived from the Socket Mode article, without mentioning need of signing secret.)

image