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;
}
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:
Here are the exact steps:
Try again after that and let me know how it goes.
Regards,
Mark C
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.