首页 > 解决方案 > 如何在 ASP.NET 中将 Google SSO CallbackPath 设置为 HTTPS?

问题描述

目前有一个项目使用Microsoft.Owin.Security.GoogleGoogle SSO 的包来访问网站。该网站位于处理 HTTPS 的负载平衡器后面。在 GCP 中,授权的重定向 URI 是http://example.com/signin-google. 今天收到来自 Google 的消息,说 HTTP 重定向 URI 已弃用,需要更新为 HTTPS。

使用 Startup.Auth.cs 中的以下代码对其进行配置:

app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    Provider = new CookieAuthenticationProvider
    {
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
            validateInterval: TimeSpan.FromMinutes(30),
            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
    }
});            
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);


app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
    ClientId = "myid",
    ClientSecret = "mysecret"              
});

如何将回调路径设置为 https?我注意到有一个 CallbackPath 选项,但这似乎只是为了将默认 /signin-google 更改为其他内容。

标签: asp.netgoogle-oauth

解决方案


推荐阅读