Exemple #1
0
        public static AuthenticationBuilder AddIdentityJwtRefreshToken <BearerTokenType>(this AuthenticationBuilder authenticationBuilder, string authenticationScheme, JwtBearerAuthenticationOptions options)
            where BearerTokenType : class, IBearerTokenEntity
        {
            authenticationScheme = authenticationScheme ?? throw new ArgumentNullException(nameof(authenticationScheme));

            return(addIdentityJwtRefreshToken <BearerTokenType>(authenticationBuilder,
                                                                configureOptions => authenticationBuilder.AddJwtBearer(authenticationScheme, configureOptions),
                                                                options));
        }
Exemple #2
0
 private static void validateJwtBearerAuthenticationOptions(JwtBearerAuthenticationOptions options)
 {
     options = options ?? throw new ArgumentNullException(nameof(options));
     Validator.ValidateObject(options, new ValidationContext(options), true);
 }
Exemple #3
0
        private static AuthenticationBuilder addIdentityJwtRefreshToken <BearerTokenType>(AuthenticationBuilder authenticationBuilder, Action <Action <JwtBearerOptions> > addJwtBearer, JwtBearerAuthenticationOptions options)
            where BearerTokenType : class, IBearerTokenEntity
        {
            validateJwtBearerAuthenticationOptions(options);

            addJwtBearer(jwtBearerOptions => {
                jwtBearerOptions.IncludeErrorDetails  = options.IncludeErrorDetails;
                jwtBearerOptions.RequireHttpsMetadata = false;

                jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = options.TokenSigningKey,
                    /// Is mandatory for <see cref="TokenValidatedContextTools.ValidateRefreshTokenIdClaim"/>.
                    SaveSigninToken  = true,
                    ValidateIssuer   = false,
                    ValidateAudience = false,
                };

                jwtBearerOptions.Events = new JwtBearerEvents()
#if DEBUG
                {
                    OnAuthenticationFailed = (context) => {
                        return(Task.CompletedTask);
                    }
                }
#endif
                                          .WhenTokenValidated(
                    // The order matters! When validating, the user
                    // related identity is added to the claims principal.
                    TokenValidatedContextTools.ValidateRefreshTokenIdClaim <BearerTokenType>,
                    TokenValidatedContextTools.ValidateSecurityStamp);
            });

            return(authenticationBuilder);
        }
Exemple #4
0
 public static AuthenticationBuilder AddJwtAccessToken(this AuthenticationBuilder authenticationBuilder, JwtBearerAuthenticationOptions options)
 {
     return(addIdentityJwtAccessToken(authenticationBuilder,
                                      configureOptions => authenticationBuilder.AddJwtBearer(AuthenticationDefaults.AccessTokenBearerScheme, configureOptions),
                                      options));
 }
Exemple #5
0
        public static AuthenticationBuilder AddJwtAccessToken(this AuthenticationBuilder authenticationBuilder, string authenticationScheme, JwtBearerAuthenticationOptions options)
        {
            authenticationScheme = authenticationScheme ?? throw new ArgumentNullException(nameof(authenticationScheme));

            return(addIdentityJwtAccessToken(authenticationBuilder,
                                             configureOptions => authenticationBuilder.AddJwtBearer(authenticationScheme, configureOptions),
                                             options));
        }
Exemple #6
0
        private static AuthenticationBuilder addIdentityJwtAccessToken(AuthenticationBuilder authenticationBuilder, Action <Action <JwtBearerOptions> > addJwtBearer, JwtBearerAuthenticationOptions options)
        {
            validateJwtBearerAuthenticationOptions(options);

            addJwtBearer(jwtBearerOptions => {
                jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = options.TokenSigningKey,
                    ValidateIssuerSigningKey = true,
                    ValidateAudience         = false,
                    ValidateIssuer           = false
                };
            });

            return(authenticationBuilder);
        }
Exemple #7
0
 public static AuthenticationBuilder AddIdentityJwtRefreshToken(this AuthenticationBuilder authenticationBuilder, JwtBearerAuthenticationOptions options) =>
 AddIdentityJwtRefreshToken <BearerTokenEntity>(authenticationBuilder, options);
Exemple #8
0
 public static AuthenticationBuilder AddIdentityJwtRefreshToken <BearerTokenType>(this AuthenticationBuilder authenticationBuilder, JwtBearerAuthenticationOptions options)
     where BearerTokenType : class, IBearerTokenEntity
 {
     return(addIdentityJwtRefreshToken <BearerTokenType>(authenticationBuilder,
                                                         configureOptions => authenticationBuilder.AddJwtBearer(AuthenticationDefaults.IdentityRefreshTokenBearerScheme, configureOptions),
                                                         options));
 }