Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How do I refresh a token

- My first access token get expired, now I want a new token without any User interface.

- I tried below in terminal,  

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d 
grant_type=refresh_token -d refresh_token={refresh_token}

but getting, below error

{"error_description": "Invalid refresh_token", "error": "invalid_request"}

 

Questions :

 1. What parameter should we pass to refresh_token? we need a new access token then why need this field?

 

I tried, expired token and new  access token(created using UI) as well but it not worked

 

Please help me to understand what parameter should we pass to the refresh_token

And how can I generate new token using terminal/curl

 

Thanks

 

 

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Nov 30, 2020

Hi Arun,

When you generated your very first access token with a command like

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code={code}

the output should have been like this:

{
"access_token" : 5cEig-w1wXrlbM876XY1Nu-w5WfObqP0EOYo2JOPzs615QxZTqI9z8Gsy_21yX23Uspwblt8eKeBAcwpCrHY=,
"scopes": "repository",
"expires_in" : 7200,
"refresh_token" : 4Etiw6UP808AU3rIoUW,
"token_type" : bearer
}

You need to use the value of the field 'refresh_token' above in your call.

Afterwards, when you execute the following command with this value for the refresh token

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token={refresh_token}

you will get in the output a new authorization code, and a new refresh token which you can use after the 2 hours expiry, and so on.

Please feel free to let me know if you have any questions.

Kind regards,
Theodora

Hi Theodora

Thanks for quick response.

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code={code}

 When we are using the {code}, parameter do we have any expiry for it? Because it seems get invalid once get used.

{"error_description": "The specified code is not valid.", "error": "invalid_grant"}

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Dec 01, 2020

Hi Arun,

The following command

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code={code}

you only use it once, in the beginning.

After the first time you use it, you execute the other command:

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token={refresh_token}

After the 2 hours expiry, you also use

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token={refresh_token}

This will give you both an authorization code and a refresh token to use the next time you execute it.

Does this help?

Kind regards,
Theodora

It Help me lot.

Thanks Theodora

Like Theodora Boudale likes this

when executing 

curl -X POST -u "{key}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code={code}

 

{"error": "invalid_grant", "error_description": "The specified code is not valid."}

 

what's the problem then? 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events