Beispiel #1
0
        public AuthenticationTicket Unprotect(string protectedText, string purpose)
        {
            var principal = _tokenValidator.ValidateToken(protectedText,
                                                          TokenGenerator.CreateTokenValidationParameters(_secretKey, _encryptionKey), out _);

            return(new AuthenticationTicket(principal, new AuthenticationProperties(), "JWT"));
        }
        public static IServiceCollection UseAuthentication(this IServiceCollection services, AuthOptions tokenOptions)
        {
            var jwtTokenValidator = new JwtSecurityTokenHandler();
            var validator         = new TokenValidator(jwtTokenValidator);

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = TokenGenerator.CreateTokenValidationParameters(tokenOptions.SecretKey, tokenOptions.EncryptionKey);
                options.RequireHttpsMetadata      = false;
                //todo refactor to default to true for prod and false for dev
            });
            return(services);
        }