07-12-2022 19:09
07-12-2022 19:09
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'
07-13-2022 10:44
07-13-2022 10:44
Are you specifying the header
Authorization: Basic <basic_token>?
07-16-2022 20:48
07-16-2022 20:48
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
07-25-2022 15:06
07-25-2022 15:06
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.