我正在尝试使用 ASP.NET 5 (rc1-final)、Identity 和 MS.AspNet.Authentication.OAuth 中间件将我正在构建的网站连接到 FitBit。我打算将授权授予流程用于 OAuth 2.0。我在 FitBit 上设置了应用程序(详情如下),我的 Startup.cs 看起来像:
app.UseIdentity();
app.UseOAuthAuthentication(options =>
{
options.AuthenticationScheme = "FitBit-AccessToken";
options.AuthorizationEndpoint = "https://www.fitbit.com/oauth2/authorize";
options.TokenEndpoint = "https://api.fitbit.com/oauth2/token";
options.SaveTokensAsClaims = true;
options.CallbackPath = new PathString("/signing-fitbit-token/");
options.ClientId = "[MY ID STRIPPED OUT]";
options.ClientSecret = "[MY SECRET STRIPPED OUT]";
options.DisplayName = "FitBit";
options.Scope.Add("activity");
options.Scope.Add("heartrate");
options.Scope.Add("location");
options.Scope.Add("nutrition");
options.Scope.Add("profile");
options.Scope.Add("settings");
options.Scope.Add("sleep");
options.Scope.Add("social");
options.Scope.Add("weight");
options.AutomaticAuthenticate = true;
});
当我点击登录按钮时,我被定向到 FitBit 上的授权页面,但是当我点击授权时,我看到了 ASP.NET 开发错误页面:
An unhandeled exception occurred while processing the request.
HttpRequestException: Response status code does not indicate success: 401 (Unauthorized)
System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
我确实在这里读到了一些 OAuth 端点(即雅虎)他们不喜欢 localhost。因此,我使用 localhost 进行了尝试,并将我的主机文件修改为不同的域。我已确保我传入的重定向 url 是在 FitBit 上为应用程序注册的。
这个错误来自我的网站,并且已经到了交换访问令牌代码的地步。我有提琴手打开我有点迷失从这里去哪里。我在 http 上运行(因为这是本地开发,我还没有 ssl 证书),但我不完全确定这是否重要。