相关疑难解决方法(0)

如何使用刷新令牌续订访问令牌?

我正在使用带有OWIN的ASP.NET MVC 5.

我做了很多研究,但没有找到如何使用刷新令牌续订访问令牌.

我的方案是:用户第一次访问我的应用时,他或她授予访问我读取API返回的刷新令牌的帐户的权限.当用户返回我的应用程序时,我需要根据"刷新令牌"刷新访问令牌.

有人可以提供一些代码吗?

这是我到目前为止所取得的成就:

Startup.Auth.cs:

    var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
    {
        Caption = "Google+",
        ClientId = Parameters.Instance.Authentication.oAuth.GooglePlus.ClientId,
        ClientSecret = Parameters.Instance.Authentication.oAuth.GooglePlus.ClientSecret,
        CallbackPath = new PathString("/oauth-login-return"),
        Provider = new GoogleOAuth2AuthenticationProvider
        {
            OnAuthenticated = async context =>
            {
                context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Identity.FindFirstValue(ClaimTypes.Name)));
                context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Identity.FindFirstValue(ClaimTypes.Email)));
                context.Identity.AddClaim(new Claim("picture", context.User.GetValue("picture").ToString()));
                context.Identity.AddClaim(new Claim("profile", context.User.GetValue("profile").ToString()));
                context.Identity.AddClaim(
                    new Claim(Parameters.Instance.Authentication.oAuth.GooglePlus.AccessTokenClaimType,
                        context.AccessToken));
            }
        }
    };
    googleOAuth2AuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/plus.login");
    googleOAuth2AuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
Run Code Online (Sandbox Code Playgroud)

AuthenticationController:

[HttpPost]
[AllowAnonymous]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
    RedirectIfAuthenticated();

    return new ChallengeResult(provider, Url.Content("~/oauth-login-callback"));
}

[ActionName("oauth-login-back")]
public …
Run Code Online (Sandbox Code Playgroud)

c# oauth-2.0 google-oauth owin asp.net-mvc-5

15
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net-mvc-5 ×1

c# ×1

google-oauth ×1

oauth-2.0 ×1

owin ×1