Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable get access token with exchange of 'Code'

I have selected 'OAuth 2.0 Application Type' as 'Client' and 'Flow Type' as 'Authorization Code Flow'

I am able to get the authorization code, but unable to get 'Access Token' using authorization code. I am trying it from an asp.net we application.

My Code as follows:

Url for code : (Generated by fitbit wesite)

"https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=xxxx&redirect_uri=https://local... respiratory_rate&expires_in=604800";

 

string code = Request.Params["code"];
string code_verifier = "01234567890123456789012345678901234567890123456789";
var authoken = Base64Encode("2xxxxx" + ":" + "axxxxxxxxxxxxxxxxxxxxxxxx");

var url = "https://api.fitbit.com/oauth2/token";
var client = new RestClient(url);
var request = new RestRequest(url, Method.Post);
request.AddHeader("Authorization", "Basic " + authoken);
var body = new
{
clientid = "2xxxxx",
code = code,
code_verifier = code_verifier,
grant_type = "authorization_code",
};
var bodyy = JsonConvert.SerializeObject(body);
request.AddBody(bodyy, "application/x-www-form-urlencoded");
RestResponse response = client.Execute(request);
var output = response.Content;

Response :
{"errors":[{"errorType":"invalid_request","message":"Missing 'grant_type' parameter value.
Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}

 

Note : If I try with the suggested approach in documentation  

POST https://api.fitbit.com/oauth2/token
Content-Type: application/x-www-form-urlencoded

client_id=ABC123&code=<authorization_code>&code_verifier=<code_verifier>&grant_type=authorization_code

 I am getting 'Invalid Authorization'

Best Answer
0 Votes
3 REPLIES 3

Hi @JanakiramAngara 

 

Are you specifying the header

 

Authorization: Basic <basic_token>?

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

Hi Gordon,

thanks for the replay,

Yes, I am sending a base64 encoded value of '(ClientId : Client Secret) as mentioned in documentation.

You can see that in my code above  like this   "request.AddHeader("Authorization", "Basic " + authoken);"

-ragards

Best Answer
0 Votes

Are you still receiving the error ""Missing 'grant_type' parameter value."   If so, would you please reproduce the error again, and private message me your client ID so I can search our logs to determine what is going on.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes