Пример #1
0
        /// <summary>
        /// 添加Jwt授权
        /// </summary>
        /// <param name="build"><see cref="AuthenticationBuilder"/></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder build, Action <AccessTokenOptions> action)
        {
            AccessTokenOptions options = new AccessTokenOptions();

            action?.Invoke(options);
            return(build.AddJwtBearer(options));
        }
Пример #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public PostConfigureTokenAuthenticationOptions(IAccessTokenStore accessTokenStore, IOptions <AccessTokenOptions> accessTokenOptions)
        {
            if (accessTokenOptions == null)
            {
                throw new ArgumentNullException(nameof(accessTokenOptions));
            }

            this.accessTokenStore   = accessTokenStore ?? throw new ArgumentNullException(nameof(accessTokenStore));
            this.accessTokenOptions = accessTokenOptions.Value;
        }
Пример #3
0
 public AuthService(
     UserManager <User> userManager,
     IEmailService emailService,
     IResetPasswordTokenProvider resetPasswordTokenProvider,
     IOptions <AccessTokenOptions> tokenOption)
 {
     ValidateTokenOptions(tokenOption.Value);
     _userManager  = userManager;
     _emailService = emailService;
     _resetPasswordTokenProvider = resetPasswordTokenProvider;
     _tokenOptions = tokenOption.Value;
 }
 /// <summary>
 /// 构造内存缓存式访问令牌存储
 /// </summary>
 /// <param name="memoryCache"></param>
 /// <param name="accessTokenOptions"></param>
 public MemoryCecheAccessTokenStore(IMemoryCache memoryCache, IOptions <AccessTokenOptions> accessTokenOptions)
 {
     cache = memoryCache;
     this.accessTokenOptions = accessTokenOptions.Value;
 }
Пример #5
0
        public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder build, AccessTokenOptions options)
        {
            build.Services.AddSingleton <IAccessTokenGenerate>(new AccessTokenGenerate(options));
            var tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = options.SigningCredentials.Key,
                ValidateIssuer           = true,
                ValidIssuer           = options.Issuer,
                ValidateAudience      = true,
                ValidAudience         = options.Audience,
                ValidateLifetime      = true,
                ClockSkew             = TimeSpan.Zero,
                RequireExpirationTime = true
            };

            build.AddJwtBearer(options.DefaultScheme, opt =>
            {
                opt.RequireHttpsMetadata      = options.RequireHttpsMetadata;
                opt.TokenValidationParameters = tokenValidationParameters;
            });
            return(build);
        }