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

Unable to exchange code for Token. Getting redirect_url mismatch error.

I'm using Fitbit.NET to implement the integration into my api. I'm able to authenticate and get a code back for the server. But when I attemp to exchange it for an token. I get an error stating `redirect_url mismatch`.

 

URL Received From Fitbit API

http://localhost:49294/api/oauth2/callback?code=ba6de3....2b41e5

 

Callback URL for application @ dev.fitbit.com

http://localhost:49294/api/oauth2/callback

 

Request User Authorization URL

 

 

string authorizationLink;
try
{
    string[] scopes = {"profile", "activity", "heartrate", "weight", "location", "sleep", "nutrition"};
    authorizationLink = Authenticator().GenerateAuthUrl(scopes);
}
catch (Exception e)
{
    AppUtils.LogException(" FitbitHandler/RequestUserAuthorizationUrl ", e);
    authorizationLink = string.Empty;
}
return authorizationLink;

Get User Token

 

 

 

public async Task<OAuth2AccessToken> GetUserToken(string code)
{
    if (_requestToken != null)
        return _requestToken;

    _requestToken = await Authenticator().ExchangeAuthCodeForAccessTokenAsync(code);
    return _requestToken;
}

Authenticator

 

 

 

private OAuth2Helper Authenticator()
{
    var appCredentials = new FitbitAppCredentials
    {
       ClientId = _consumerKey,
       ClientSecret = _consumerSecret
    };
   return new OAuth2Helper(appCredentials, CallbackUrl);
}

 

 

Best Answer
0 Votes
3 REPLIES 3

Perhaps it's better to file an issue on the library's repository, since this library was not created by Fitbit.

 

This error means that the redirect_uri provided in the Access Token Request does not match the redirect_uri specified on the Authorization Page URL.

Best Answer

@JeremiahFitbit Thanks for you response. I've already opened an issue here, but they've yet to respond. Is the callback_url equal to the redirect_url? If not how do I find the redirect_url?

Best Answer
0 Votes

@antarr Redirect_uri parameter should match the callback URL in the app settings.

Andrew | Community Moderator, Fitbit

What motivates you?

Best Answer
0 Votes