OpenTouryoProject / MultiPurposeAuthSite

汎用認証サイトは、ASP.NET Identity および JSON Web Token (JWT)によって強化されたOAuth 2.0およびOpenID ConnectのIdentity Provider (Idp) および Security Token Service (STS)です。(Multi-purpose Authentication Site is Identity Provider (Idp) and Security Token Service (STS) of OAuth 2.0 and OpenID Connect powered by ASP.NET Identity and JSON Web Token (JWT).)
https://opentouryo.osscons.jp/index.php?汎用認証サイト(Multi-purpose%20Authentication%20Site)
9 stars 7 forks source link

SecurityStamp is not worked in ASP.NET Identity Core version. #141

Closed daisukenishino2 closed 4 years ago

daisukenishino2 commented 4 years ago

Requirement

daisukenishino2 commented 4 years ago

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    Provider = new CookieAuthenticationProvider
    {
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
        // SecurityStampValidatorによる検証の間隔
        validateInterval: Config.SecurityStampValidateIntervalFromSeconds,
        // ClaimsIdentityを返すdelegate
        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
    },
    ExpireTimeSpan = TimeSpan.FromMinutes(30)
});

↓ ↓ ↓

services.AddScoped<ISecurityStampValidator, SecurityStampValidator<IdentityUser>>();
services.Configure<SecurityStampValidatorOptions>(options =>
{
    options.ValidationInterval = TimeSpan.FromSeconds(10);
});
AuthenticationBuilder authenticationBuilder = services.AddAuthentication();
authenticationBuilder.AddCookie(options =>
    {
        ...
        options.Events = new CookieAuthenticationEvents()
        {
            OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync
        };
    });