예제 #1
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();

            var authenticationConfiguration = new AuthenticationConfiguration
            {
                RequireSsl = false
            };

            authenticationConfiguration.AddBasicAuthentication((userName, password) =>
            {
                return userName == "filip" && password == "abc";
            }, AuthenticationOptions.ForHeader("MyAuthorization"));

            config.MessageHandlers.Add(new AuthenticationHandler(authenticationConfiguration));
            appBuilder.UseWebApi(config);
        }
예제 #2
0
        public static void AddJsonWebToken(
            this AuthenticationConfiguration configuration,
            TokenValidationParameters validationParameters,
            AuthenticationOptions options,
            AuthenticationScheme scheme,
            Dictionary <string, string> claimMappings = null)
        {
            var handler = new IdentityModelJwtSecurityTokenHandler(validationParameters, claimMappings);

            configuration.AddMapping(new AuthenticationOptionMapping
            {
                TokenHandler = new SecurityTokenHandlerCollection {
                    handler
                },
                Options = options,
                Scheme  = scheme
            });
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var options = new AuthenticationOptions()
            {
                RequestType = HttpRequestType.AuthorizationHeader,
                Name = "Authorization",
                Scheme = "SAML"
            };

            var registry = new ConfigurationBasedIssuerNameRegistry();
            registry.AddTrustedIssuer("18145fb6b5d96b3cc34ec7599f12172bb93c68ef", "DummySTS");

            var adfsConfig = new SecurityTokenHandlerConfiguration();
            adfsConfig.AudienceRestriction.AllowedAudienceUris.Add(new Uri("urn:claimsdemo:mvc5http"));
            adfsConfig.IssuerNameRegistry = registry;
            adfsConfig.CertificateValidator = X509CertificateValidator.None;

            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection certificates = store.Certificates;
            X509Certificate2Collection matchingCertificates = certificates.Find(
                X509FindType.FindByThumbprint,
                "a2028f8e7f7b082cd35e81fd0ca0b70b04651abf", false);
            X509Certificate2 certificate = certificates[0];

            List<SecurityToken> serviceTokens = new List<SecurityToken>();
            serviceTokens.Add(new X509SecurityToken(certificate));
            SecurityTokenResolver serviceResolver =
                SecurityTokenResolver.CreateDefaultSecurityTokenResolver(
                    serviceTokens.AsReadOnly(), false);
            adfsConfig.ServiceTokenResolver = serviceResolver;

            var config = new AuthenticationConfiguration
            {
                RequireSsl = false
            };

            config.AddSaml11(adfsConfig, options);

            return config;
        }
예제 #6
0
 public HttpAuthentication(AuthenticationConfiguration configuration)
 {
     Configuration = configuration;
 }
 public HttpAuthentication(AuthenticationConfiguration configuration)
 {
     Configuration = configuration;
 }
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpMessageHandler innerHandler) : this(new HttpAuthentication(configuration), innerHandler)
 {
 }
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpConfiguration httpConfiguration = null) : this(new HttpAuthentication(configuration), httpConfiguration)
 {
 }
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpMessageHandler innerHandler) : this(new HttpAuthentication(configuration), innerHandler) {}
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpConfiguration httpConfiguration = null) : this(new HttpAuthentication(configuration), httpConfiguration) {}