ASP.NET核心身份到期(谷歌OAuth)

我目前正在使用ASP.NET核心身份。我无法弄清楚延长会话长度的设置,但我一直在注销 - 我假设有一个大约20分钟的失效时间,但我找不到该设置。请注意,我将Google用作外部OAuth。ASP.NET核心身份到期(谷歌OAuth)

 services.AddIdentity<ApplicationUser, IdentityRole>(o => 

{

o.Password.RequireDigit = false;

o.Password.RequireLowercase = false;

o.Password.RequireUppercase = false;

o.Password.RequireNonAlphanumeric = false;

o.Password.RequiredLength = 6;

o.SecurityStampValidationInterval = TimeSpan.FromHours(8);

o.Cookies.ExternalCookie.ExpireTimeSpan = TimeSpan.FromHours(8);

o.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromHours(8);

})

.AddEntityFrameworkStores<ApplicationDbContext>()

.AddDefaultTokenProviders();

app.UseIdentityServer();

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions

{

Authority = $"http://localhost:55504/",

RequireHttpsMetadata = false,

AllowedScopes =

{

IdentityServerConstants.StandardScopes.OpenId,

IdentityServerConstants.StandardScopes.Profile,

IdentityServerConstants.StandardScopes.Email,

"name",

"given_name",

"family_name",

"role"

}

});

var googleOptions = serviceProvider.GetRequiredService<GoogleOptions>();

app.UseGoogleAuthentication(new GoogleOptions

{

AuthenticationScheme = "Google",

SignInScheme = "Identity.External",

ClientId = googleOptions.ClientId,

ClientSecret = googleOptions.ClientSecret

});

回答:

这个问题\答案是特定于Identity Server的4

你会做这样的事情在你的配置:

app.UseGoogleAuthentication(new GoogleOptions 

{

SignInScheme = "Identity.External", // this is the name of the cookie middleware registered by UseIdentity()

ClientId = Configuration["ExternalAuthentication:Google:ClientId"],

ClientSecret = Configuration["ExternalAuthentication:Google:ClientSecret"]

});

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions

{

Authority = $"http://localhost:55504/",

RequireHttpsMetadata = false,

AllowedScopes =

{

IdentityServerConstants.StandardScopes.OpenId,

IdentityServerConstants.StandardScopes.Profile,

IdentityServerConstants.StandardScopes.Email,

"name",

"given_name",

"family_name",

"role"

}

// CookieLifetime default is 10 Hours

Authentication.CookieLifetime = TimeSpan.FromHours(24);

// Default CookieSlidingExpiration = false;

Authentication.CookieSlidingExpiration = true;

});

,并在您ConfigureServices

// Identity 

// https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity

// http://docs.identityserver.io/en/release/quickstarts/6_aspnet_identity.html

services.AddIdentity<ApplicationUser, IdentityRole>(o => {

// configure identity options

o.Password.RequireDigit = false;

o.Password.RequireLowercase = false;

o.Password.RequireUppercase = false;

o.Password.RequireNonAlphanumeric = false;

o.Password.RequiredLength = 6;

})

.AddEntityFrameworkStores<AuthDbContext>()

.AddDefaultTokenProviders();

以上是 ASP.NET核心身份到期(谷歌OAuth) 的全部内容, 来源链接: utcz.com/qa/267070.html

回到顶部