Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,268
Community Members
 
Community Events
165
Community Groups

Error trying to retrieve access_token through OAuth2.0

I am trying to get an access token through OAuth2.0 but everytime I try to do it, I just receive the error below.

Error:: "Cannot use client_credentials with a consumer marked as \"public\". Calls for auto generated consumers should use urn:bitbucket:oauth2:jwt instead.", "error": "invalid_grant"}

 

I am trying to send a POST request through HTTPClient but I am not sure what I am doing wrong here.

Code below:

private static async Task<Token> GetEligibleToken()
{
var client = new HttpClient();
string baseAddress = "https://bitbucket.org/site/oauth2/access_token";

string grant_type = "client_credentials";
string client_id = "id";
string client_secret = "secret";

var form = new Dictionary<string, string>
{
{"grant_type", grant_type},
{"client_id", client_id},
{"client_secret", client_secret},
};

HttpResponseMessage tokenResponse = await client.PostAsync(baseAddress, new FormUrlEncodedContent(form));
var jsonContent = await tokenResponse.Content.ReadAsStringAsync();
Token tok = JsonConvert.DeserializeObject<Token>(jsonContent);
Console.WriteLine(tok);
return tok;
}

1 answer

0 votes
Mark C Atlassian Team Jun 01, 2022

Hi @tommythongsythavong

Welcome to the community.

Based on the error message, I believe you'll need to make your consumer keys private.
You'll need to tick the "This is a private consumer" checkbox similar to the screenshot below:
private_consumer.png
Here are the exact steps:

  1. Go to your workspace - https://bitbucket.org/workspace_id_here/
  2. Click Settings
  3. Click OAuth consumers (Under Apps and Features)
  4. Click the 3-dotted-icon next to your consumer keys > Click Edit
  5. Lastly, tick the "This is a private consumer" checkbox to make it private

Try again after that and let me know how it goes.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,227 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you