IBM-Cloud / openwhisk-slackapp

A serverless Slack app built with Slack Events API and IBM Cloud Functions
Other
27 stars 28 forks source link

Invalid_code error when trying to register through Slack Button #9

Closed DarrenZastruga closed 3 years ago

DarrenZastruga commented 6 years ago

I keep getting the message "Registration failed" when I click the "Add to Slack" button. Checking the activation poll, I see the message "ok: false, error: 'invalid_code'." But for the life of me, I can't figure out what the problem is with the code returned by the url. The code in the activation poll works in the oauth.access tester on the Slack API documentation site, so I can't figure it out. Can you review the code and see what's going on?

So far, I haven't been able to get the chatbot working in my workspace. I get no response when I attempt direct messages, and using the slash command only returns "Team not found."

Thanks for any help you can provide!

l2fprod commented 6 years ago

@DarrenZastruga

I went through the steps today and updated one section https://github.com/IBM-Bluemix/openwhisk-slackapp/#add-the-app-to-your-team as the Slack UI changed a bit but other than that no issue and it worked as expected.

Are you on Windows or Linux/macOS?

DarrenZastruga commented 6 years ago

@l2fprod I'm using macOS.

I'm still getting the Registration Failed return when I click the Slack Button. The code returned in the URL still returns ok in Slack's Tester in the API documentation. Also, the challenge to the URL Events Subscription keeps failing - that's new.

l2fprod commented 6 years ago

@DarrenZastruga

few things to check:

DarrenZastruga commented 6 years ago

@l2fprod Thanks, I went back and re-did the steps, confirming the local.env values, the Cloudant setup, and the URLs. I'm still getting "Registration failed" when I click the Slack Button.

However, I note my app has been installed in my workspace. So maybe the registration is failing because the app has already been installed? I tried uninstalling the app and then clicking the Slack Button, but still "Registration failed."

Yet even though I see the app online in my workspace, I get no response back when I message my app directly. In the activation poll, I see it says, "Error team not found." (I note aaronmcohen also wrote about a similar issue in #8.) I also get a "Team not found" response in Slack when I try to test the slash command in the channel. So maybe some error in the way the app processes messages?

l2fprod commented 6 years ago

@DarrenZastruga

If the registrations database is empty then the command and messages won't work. You have to pass the registration phase.

From where are you adding the app? Yesterday when I tried, I updated the steps for the "Add to Slack". I had to go through "Manage Distribution" for the registration to work.

DarrenZastruga commented 6 years ago

@l2fprod Yes, I don't see any team_id added to the registrations database. Below is what's currently in the registrations database, so you can see whether that looks right or not. I also have been going through "Manage Distribution."

{ "_id": "_design/bots", "_rev": "4-e466ee8aad75fd2b8a8f8a5d081b31a2", "views": { "by_team_id": { "map": "function (doc) {\n if (doc.type == \"bot-registration\") {\n emit(doc._id, 1);\n }\n}" } }, "language": "javascript" }

l2fprod commented 6 years ago

@DarrenZastruga

That one looks good.

when the action outputs "Registration failed", it should also output the response from Slack in the Cloud Functions activation log. What do you see here? Keep "wsk activation poll" during the registration process to catch any error.

not simple to debug all this. If you have the chance to record a video of all your steps maybe we could catch something

DarrenZastruga commented 6 years ago

@l2fprod

RegistrationFailed_WskActivationPollOutput.txt

Attached is what I see in the activation poll after I last tried to register (with personal info XX'd out). I have verified that the client ID, client Secret, and CloudantURL returned in the log were correct. When I test this using the code returned, it works in the Slack oauth tester, so I'm confused as to why it doesn't work when running the slackapp-register file with the Slack button.

l2fprod commented 6 years ago

@DarrenZastruga

In https://github.com/IBM-Bluemix/openwhisk-slackapp/blob/master/actions/slackapp-register.js#L32 I noticed I don't encode the parameters, maybe the client id, secret or code contains one character that should be encoded and it leads to an issue. Do you see any character that should be encoded in the client id, secret, token or code? Specially in the personal info XXX

DarrenZastruga commented 6 years ago

@l2fprod

No, the parameters listed in the activation poll match exactly those for my Slack app. I had originally been thinking the error had to do with the code returned by the oauth url. The oauth.access Slack API documentation says that the "invalid_error" is returned when the value passed for the code is invalid, and the code given in the activitation poll (266898532515.273542513718.edb4391289a85b37def5b90df65cee371ecce7611b977df0f0e8f0d9de4b0250) is a very different format than the example given by the Slack API documentation (ccdaa72ad).

Maybe it has to do with the request URL? I'm not very familiar with node.js - where does it get the code from in the first place?

l2fprod commented 6 years ago

@DarrenZastruga

the "code" is generated and sent by Slack to the Cloud Functions and received by the function here https://github.com/IBM-Bluemix/openwhisk-slackapp/blob/master/actions/slackapp-register.js#L19

rehelm3 commented 6 years ago

Nice.