Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

OAuth "Exchange authorization code for access token" step gives error but works on localhost

Rahul Midha
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 17, 2024

When authenticating a user, the app successfully reaches the callback URL API Endpoint but while generating token via:

const { data } = await axios.post(
`https://auth.atlassian.com/oauth/token`,
{
grant_type: "authorization_code",
client_id: process.env.INTEGRATIONS_JIRA_CLIENT_ID,
client_secret: process.env.INTEGRATIONS_JIRA_CLIENT_SECRET,
code,
redirect_uri: "https://staging-api.mydomain.com/api/v1/integration/jira/callback",
},
);

It returns: 

{

"error": "access_denied",

"error_description": "Unauthorized"

}

But this works successfully in the case of localhost redirect_uri:

 

http://localhost:2000/api/v1/integration/jira/callback
I modified the callback URL in the developer settings in both cases.
The problem is that when I used the "https://staging-api.mydomain.com" host, it gave the above error.

1 answer

0 votes
Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 18, 2024

Hi,

What datatype is code? Shouldn't that be 

{ 
...
code: code,
...
}

Since you're passing an object to the request.

Rahul Midha
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 24, 2024

Hi prince, 
code is of string type here. In JavaScript, if you have a variable having name same as an object key name, you can skip writing it again.
So,

{

...

code: code,

...

}

is the same as: 

 

const code = "<string-value>";

{

...

code,

...

So, I am passing string only.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events