Hello all,
I am trying to integrate my app with slack. I used an example provided by atlassian to get me started, but I keep getting
[NEEDS_AUTHENTICATION_ERR: Authentication Required] { status: 401,serviceKey: ‘slack-bot’,options: { scopes: undefined, isExpectedError: true }
When using api.asUser().withProvider(provider, "slack-apis")
I found someone else having similar errors in the Developer Community here, but I tried changing my manifest to their solution and still got the same error.
Here is my yml
environment:
variables:
- APP_ID
- CLIENT_ID
modules:
confluence:globalPage:
- key: forms-global-page
resource: global-page
render: native
resolver:
function: resolver
title: Forms For ConfluenceTest2
route: forms-for-confluence
confluence:contentBylineItem:
- key: custom-ui-macro-hello-world
resource: macro
resolver:
function: resolver
title: Form
description: Inserts Hello world!
function:
- key: resolver
handler: index.handler
providers:
auth:
- slack-bot
permissions:
scopes:
- storage:app
- read:content:confluence
- read:confluence-content.summary
- write:confluence-content
- read:jira-work
- manage:jira-configuration
- read:page:confluence
- write:page:confluence
- write:comment:confluence
external:
fetch:
backend:
- https://slack.com
images:
- https://raw.githubusercontent.com/ChewyCorndog/Atlassian_Images/main/create_ECO_image.png
- https://raw.githubusercontent.com/ChewyCorndog/Atlassian_Images/main/edit_ECO_image.png
resources:
- key: global-page
path: src/frontend/forms-global-page.jsx
- key: macro
path: static/hello-world/build
app:
runtime:
name: nodejs22.x
id: ari:cloud:ecosystem::app/${APP_ID}
providers:
auth:
- key: slack-bot
name: slack (bot)
type: oauth2
clientId: "8226975471746.8609084015285"
remotes:
- slack-apis
bearerMethod: authorization-header
actions:
authorization:
remote: slack-apis
path: /oauth/v2/authorize
queryParameters:
scope: chat:write,chat:write.public,im:write,users:read,team:read,links:write
exchange:
remote: slack-apis
path: /api/oauth.v2.access
resolvers:
accessToken: authed_user.access_token
revokeToken:
remote: slack-apis
path: /api/auth.revoke
retrieveProfile:
remote: slack-apis
path: /api/auth.test
resolvers:
id: "bot:{{user_id}}:{{team_id}}"
displayName: "{{user}} ({{team}})"
remotes:
- key: slack-apis
baseUrl: https://slack.com
Here is my backend function
resolver.define("integrateWithSlack", async () => {
const provider = "slack-bot";
console.log("IN THE RESOLVER")
const slack = await api.asUser().withProvider(provider, "slack-apis");
console.log(await slack.hasCredentials())
if (!(await slack.hasCredentials())) {//LETS SEE WHAT HAPPENS IF YOU REQUEST CREDENTIALS WHEN YOU ALREADY HAVE THEM
console.log("IN THE CRED AREA")
try{
await slack.requestCredentials();
}
catch (error){
console.log(error)
}
await slack.requestCredentials();
}
});
The 401 error appears upon clicking my slack integration button, which also causes my global page contents to be replaced by the error message in picture 1 below. It still lets me configure access and go through all the steps to authorize my slack app, but then gives me the message “Could not extract id from the response”
Upon pressing the integrate slack button in my app, I get these pages in sequential order:
Any help is very appreciated!