【问题标题】:redirect_url mismatch error when exchanging code for token交换令牌代码时出现redirect_url不匹配错误
【发布时间】:2017-06-18 09:23:09
【问题描述】:

我正在尝试在我的 WebApi 应用程序中使用 Fitbit 交换令牌代码。我不断收到异常,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;

获取用户令牌

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);
}

【问题讨论】:

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


    【解决方案1】:

    您的重定向网址应与您在应用设置中提供的内容一致。

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 2013-12-25
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多