现在,这是我的代码,用于将github oauth添加到我的Web应用程序。
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddGitHub(Options =>
{
Options.ClientId = "client";
Options.ClientSecret ="secret";
Options.Scope.Add("repo");
Options.SaveTokens = true;
})
我可以从以下代码中获取访问令牌:
var token = HttpContext.GetTokenAsync("access_token");
有没有一种方法可以获取到期时间?
答案 0 :(得分:0)
所以看起来我需要添加一个范围
.AddMicrosoftAccount(Options =>
{
Options.ClientId = "client";
Options.ClientSecret ="secret";
Options.Scope.Add("repo");
Options.SaveTokens = true;
Options.Scope.Add("offline_access");
})
然后我可以通过调用来获取刷新令牌:
var token = HttpContext.GetTokenAsync("refresh_token");