【发布时间】: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