交换令牌

时间:2017-02-01 15:05:43

标签: c# .net asp.net-web-api oauth-2.0 owin

我尝试使用Fitbit在我的WebApi应用程序中实现代码交换代码。我一直得到例外,Message = "Redirect_uri mismatch: http://localhost:49294/api/... Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."

RequestUserAuthorizationUrl

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;

GetUserToken

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

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

身份验证

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

1 个答案:

答案 0 :(得分:1)

您的重定向网址应与您在应用设置中提供的网址相匹配。