【问题标题】:What are the standard names of the protocols behind UseOAuthAuthentication and UseGoogleAuthentication?UseOAuthAuthentication 和 UseGoogleAuthentication 背后的协议的标准名称是什么?
【发布时间】:2016-07-20 06:52:59
【问题描述】:

ASP.NET 安全社交示例has two ways to interact with Google.

使用OAuthAuthentication

app.UseOAuthAuthentication(new OAuthOptions
{
    AuthenticationScheme = "Google-AccessToken",
    DisplayName = "Google-AccessToken",
    ClientId = Configuration["google:clientid"],
    ClientSecret = Configuration["google:clientsecret"],
    CallbackPath = new PathString("/signin-google-token"),
    AuthorizationEndpoint = GoogleDefaults.AuthorizationEndpoint,
    TokenEndpoint = GoogleDefaults.TokenEndpoint,
    Scope = { "openid", "profile", "email" },
    SaveTokens = true
});

使用谷歌身份验证

app.UseGoogleAuthentication(new GoogleOptions
{
    ClientId = Configuration["google:clientid"],
    ClientSecret = Configuration["google:clientsecret"],
    SaveTokens = true,
    Events = new OAuthEvents()
    {
        OnRemoteFailure = ctx =>
        {
            ctx.Response.Redirect("/error?FailureMessage=" 
                + UrlEncoder.Default.Encode(ctx.Failure.Message));
            ctx.HandleResponse();
            return Task.FromResult(0);
        }
    }
});

这两种身份验证和授权的标准名称是什么?即一个 OAuth 和另一个 OpenID Connect?

选择 @987654324 @,这是结果。

context
    .User.Claims: []
    .User.Identity.Name: null
    .Authentication.GetTokenAsync("access_token"): ya29.CjAlAz3AcUnRD...
    .Authentication.GetTokenAsync("refresh_token"): null
    .Authentication.GetTokenAsync("token_type"): Bearer
    .Authentication.GetTokenAsync("expires_at"): 2016-07-19T22:49:54...

选择 @987654326 @,这是结果。

context
    .User.Claims: [
        nameidentifier: 10424487944...
        givenname: Shaun
        surname: Luttin
        name: Shaun Luttin
        emailaddress: admin@shaunl...
        profile: https://plus.google.com/+ShaunLuttin        
    ]
    .User.Identity.Name: "Shaun Luttin"
    .Authentication.GetTokenAsync("access_token"): ya29.CjAlAz3AcUnRD...
    .Authentication.GetTokenAsync("refresh_token"): null
    .Authentication.GetTokenAsync("token_type"): Bearer
    .Authentication.GetTokenAsync("expires_at"): 2016-07-19T22:49:54...

【问题讨论】:

    标签: oauth oauth-2.0 asp.net-core openid openid-connect


    【解决方案1】:

    UseOAuthAuthenticationUseGoogleAuthentication 都是 OAuth。不同之处在于 Google 中间件设置了一些特定于 Google 的默认 OAuth 选项,并添加了一个 GoogleHandler 来获取用户配置文件信息。

    换句话说,

    • UseOAuthAuthentication 是检索和访问令牌的 OAuth。

    • UseGoogleAuthentication 是 OAuth,其选项和流程经过调整,可从 Google 检索访问代码和用户配置文件信息。

    【讨论】:

      猜你喜欢
      • 2012-10-28
      • 2017-01-04
      • 2020-08-22
      • 1970-01-01
      • 2016-09-10
      • 2011-06-07
      • 2016-02-29
      • 2012-01-29
      • 2021-12-24
      相关资源
      最近更新 更多