public static void AddBasicAuthentication(this AuthenticationConfiguration configuration, Func<string, string, bool> validationDelegate, Func<string, string[]> roleDelegate, string realm = "localhost", bool retainPassword = false) { var handler = new BasicAuthenticationWithRoleSecurityTokenHandler(validationDelegate, roleDelegate); handler.RetainPassword = retainPassword; configuration.AddMapping(new AuthenticationOptionMapping { TokenHandler = new SecurityTokenHandlerCollection { handler }, Options = AuthenticationOptions.ForAuthorizationHeader(scheme: "Basic"), Scheme = AuthenticationScheme.SchemeAndRealm("Basic", realm) }); }
public static void AddJsonWebToken( this AuthenticationConfiguration configuration, string issuer, string audience, X509Certificate2 signingCertificate, Dictionary <string, string> claimMappings = null) { var validationParameters = new TokenValidationParameters() { AllowedAudience = audience, SigningToken = new X509SecurityToken(signingCertificate), ValidIssuer = issuer, }; configuration.AddJsonWebToken( validationParameters, AuthenticationOptions.ForAuthorizationHeader(JwtConstants.Bearer), AuthenticationScheme.SchemeOnly(JwtConstants.Bearer), claimMappings); }
public static void AddJsonWebToken( this AuthenticationConfiguration configuration, string issuer, string audience, string signingKey, Dictionary <string, string> claimMappings = null) { var validationParameters = new TokenValidationParameters() { AllowedAudience = audience, SigningToken = new BinarySecretSecurityToken(Convert.FromBase64String(signingKey)), ValidIssuer = issuer, }; configuration.AddJsonWebToken( validationParameters, AuthenticationOptions.ForAuthorizationHeader(JwtConstants.Bearer), AuthenticationScheme.SchemeOnly(JwtConstants.Bearer), claimMappings); }