c# - Fitbit oauth2.0 asp.net
问题描述
我收到以下代码的无效重定向 uri。
启动.cs
services.AddOAuth(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; });
FitbitController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
namespace FitBit_Oauth.Controllers
{
[Route("[controller]/[action]")]
public class FitbitController : Controller
{
[HttpGet]
public IActionResult Login()
{
return Challenge(new AuthenticationProperties() { RedirectUri = $"/" });
}
}
}
我已经尝试过这个来验证 fitbit 用户并检索访问令牌,但是我得到了无效的 redirect_uri。
任何人都可以在这里建议,如何在 asp.net core MVC 中实现它?
解决方案
我不完全确定您的要求是什么,但您可以使用 Fitbit.Net而不是自己执行此操作。它并不完美,但它需要大量的腿部工作。
推荐阅读
- azure - 用于导出组成员身份的 Azure AD Powershell 脚本
- sql - 在 SQL Server 2008 中从 MM-DD-YYYY 转换为 CCYY-MM-DD
- c# - 将文本绑定到数组对象中的嵌套成员
- python - 坐标的Python函数
- django - Django:如何从 auto_add_now/auto_now 移动到可编辑的日期字段
- ios - 通过 iOS TestFlight 测试时 React Native RCTFatal + 448 崩溃
- python - 在 MPI 中应用 Reduce 和 Broadcast
- java - 为什么我不能在这里打印我的声明或任何东西?
- pandas - 如何从 xarray 中找到 pandas 数据框中的索引?
- mysql - mysqli按多列计数组