Forums

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

What's Wrong With My Token Generation.

Saikat Samanta
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!
March 29, 2021

What's wrong with my JWT generation I am using this code to generate JWTScreenshot 2021-03-29 at 9.47.35 PM.png

const jwt = require('atlassian-jwt');

const moment = require('moment');

const now = moment().utc();

const clientKey='XXXXXXXXXXXX';

const sharedSecret = 'XXXXXXXXXXXXXX';

const req = jwt.fromMethodAndUrl('GET', 'https://api.bitbucket.com/2.0/repositories/{bfd8fa1a-XXX-XXX-XXX-XXXXXXX}');

const tokenData = {

"iss": 'codelock',

"iat": now.unix(),

"exp": now.add(30, 'minutes').unix(),

"qsh": jwt.createQueryStringHash(req),

"sub": clientKey

};

const token = jwt.encode(tokenData, sharedSecret);console.log(token);

1 answer

1 accepted

1 vote
Answer accepted
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 6, 2021

Hello @Saikat Samanta ,

Welcome to the Atlassian Community!

I might not be the best person to answer development related questions, however, looking at your screenshot I can see that you are providing a wrong authorization header.

Indeed, in your screenshot I can see:

Authorization: JWT <token>

 

While it is supposed to be:

Authorization: Bearer <token>

 

Therefore, there are chances there is nothing wrong with the code to generate the JWT token and that the issue is just with the authorization header you are providing.

 

Can you kindly try to use the correct header and check if this works?

 

Finally, for the future, please notice that this is not the best place to get help on development  related questions. The right resources are listed in https://developer.atlassian.com/resources. 

Specifically:

 

 

Cheers,
Dario

Suggest an answer

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

Atlassian Community Events