Ejemplo n.º 1
0
        public static void Register(HttpConfiguration config)
        {
            var authNConfig = new AuthenticationConfiguration
                {
                    SendWwwAuthenticateResponseHeaders = false,
                    RequireSsl = false
                };

            //authNConfig.AddJsonWebToken(
            //    "TODOApi",
            //    "http://tt.com/mobile/todos",
            //    ConfigurationManager.AppSettings["acsSigningKey"]);

            authNConfig.AddJsonWebToken(
                "http://identityserver.v2.thinktecture.com/trust/cw",
                "http://tt.com/mobile/todos",
                ConfigurationManager.AppSettings["oauthSigningKey"]);

            authNConfig.AddBasicAuthentication(
                (un, pw) => un == pw); // this is the super complex basic authentication validation logic :)

            authNConfig.ClaimsAuthenticationManager =
                FederatedAuthentication.FederationConfiguration
                    .IdentityConfiguration.ClaimsAuthenticationManager;

            config.MessageHandlers.Add(new AuthenticationHandler(authNConfig));
            config.Filters.Add(new ClaimsAuthorizeAttribute());
        }
Ejemplo n.º 2
0
        public static void RegisterAuth(HttpConfiguration config)
        {
            // To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter,
            // you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166

            //OAuthWebSecurity.RegisterMicrosoftClient(
            //    clientId: "",
            //    clientSecret: "");

            //OAuthWebSecurity.RegisterTwitterClient(
            //    consumerKey: "",
            //    consumerSecret: "");

            //OAuthWebSecurity.RegisterFacebookClient(
            //    appId: "",
            //    appSecret: "");

            //OAuthWebSecurity.RegisterGoogleClient();


            var authConfig = new AuthenticationConfiguration();
            
            authConfig.AddBasicAuthentication((userName, password) =>
            {
                return Membership.ValidateUser(userName, password);
            });

            authConfig.InheritHostClientIdentity = true;

            config.MessageHandlers.Add(new AuthenticationHandler(authConfig));
        }
Ejemplo n.º 3
0
        public static void BasicAuthentication()
        {
            using (var config = new HttpConfiguration())
            using (var server = new HttpServer(config))
            using (var client = new HttpClient(server))
            {
                config.Routes.MapHttpRoute(
                    name: "Api",
                    routeTemplate: "api/{controller}/{id}",
                    defaults: new {id = RouteParameter.Optional}
                );

                var authConfig = new AuthenticationConfiguration
                {
                    InheritHostClientIdentity = true,
                    ClaimsAuthenticationManager = FederatedAuthentication
                        .FederationConfiguration
                        .IdentityConfiguration
                        .ClaimsAuthenticationManager
                };

                // You can setup authentication against membership:
                //authConfig.AddBasicAuthentication((username, password) =>
                //    Membership.ValidateUser(username, password));
                authConfig.AddBasicAuthentication((username, password) =>
                    username == Helpers.__ && password == Helpers.__);

                config.MessageHandlers.Add(new AuthenticationHandler(authConfig));

                client.DefaultRequestHeaders.Authorization =
                    new BasicAuthenticationHeaderValue("happy", "holidays");
                using (var response = client.GetAsync("http://go.com/api/authenticationkoan").Result)
                    Helpers.AssertEquality(HttpStatusCode.OK, response.StatusCode);
            }
        }
        private static AuthenticationHandler GetDefaultAuthenticationHandler()
        {
            var authConfig = new AuthenticationConfiguration();

            #region Basic Authentication
            authConfig.AddBasicAuthentication((userName, password) => { return userName == password; });
            #endregion

            //#region SWT
            //authConfig.Handler.AddSimpleWebToken(
            //    "SWT", 
            //    Constants.Issuer,
            //    Constants.Realm,
            //    "Dc9Mpi3jbooUpBQpB/4R7XtUsa3D/ALSjTVvK8IUZbg=");
            //#endregion

            #region SAML2 tokens
            var registry = new ConfigurationBasedIssuerNameRegistry();
            registry.AddTrustedIssuer("D263DDCF598E716F0037380796A4A62DF017ADB8", "TEST");

            var saml2Config = new SecurityTokenHandlerConfiguration();
            saml2Config.AudienceRestriction.AllowedAudienceUris.Add(new Uri("https://test"));
            saml2Config.IssuerNameRegistry = registry;
            saml2Config.CertificateValidator = X509CertificateValidator.None;

            authConfig.AddSaml2(saml2Config, AuthenticationOptions.ForAuthorizationHeader("Saml2"));
            #endregion

            var authHandler = new AuthenticationHandler(authConfig);
            return authHandler;
        }
        public AuthenticationHandler(AuthenticationConfiguration configuration, HttpConfiguration httpConfiguration = null)
        {
            _authN = new HttpAuthentication(configuration);

            if (httpConfiguration != null)
            {
                InnerHandler = new HttpControllerDispatcher(httpConfiguration);
            }
        }
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var authentication = new AuthenticationConfiguration
            {
                RequireSsl = false,
            };

            authentication.AddJsonWebToken(Constants.AS.IssuerName, Constants.Audience, Constants.AS.SigningKey,
                                           ClaimMappings.None);

            return authentication;
        }
        public static AuthenticationConfiguration CreateClientAuthConfig()
        {
            var authConfig = new AuthenticationConfiguration
            {
                InheritHostClientIdentity = false,
            };

            // accept arbitrary credentials on basic auth header,
            // validation will be done in the protocol endpoint
            authConfig.AddBasicAuthentication((id, secret) => true, retainPassword: true);
            return authConfig;
        }
        private static AuthenticationConfiguration CreateSessionTokenAuthenticationConfiguration()
        {
            var config = new AuthenticationConfiguration
            {
                RequireSsl = false,
                EnableSessionToken = true
            };

            config.AddBasicAuthentication((u, p) => u == p);

            return config;
        }
        private static AuthenticationConfiguration CreateSessionTokenAuthenticationConfiguration()
        {
            var config = new AuthenticationConfiguration
            {
                RequireSsl = false,
                EnableSessionToken = true,
                ClaimsAuthenticationManager = new ClaimsTransformer()
            };

            config.AddBasicAuthentication((u, p) => u == p);

            return config;
        }
Ejemplo n.º 10
0
        private AuthenticationConfiguration CreateConfiguration()
        {
            var config = new AuthenticationConfiguration
                {
                    EnableSessionToken = true,
                    RequireSsl = false,
                    SendWwwAuthenticateResponseHeaders = false
                };

            config.AddBasicAuthentication(UserCredentials.Validate);

            return config;
        }
        public static void MapRebarODataRoute(
            this HttpConfiguration config,
            string routeName,
            string routePrefix,
            IEdmModel model,
            IEnumerable<Func<DelegatingHandler>> handlers,
            string serviceIdentifier = null)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            HttpMessageHandler delegatingHandler;

            if (handlers != null)
            {
                delegatingHandler = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handlers.Select(x => x()));
            }
            else
            {
                delegatingHandler = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), null);
            }

            DelegatingHandler handler;
            var uriBuilder = new UriBuilder();

            var disableSecurity = ConfigurationManager.AppSettings[DisableSecuritySetting];
            var isSecurityDisabled = !string.IsNullOrWhiteSpace(disableSecurity) && bool.Parse(disableSecurity);
            if (uriBuilder.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase) && isSecurityDisabled)
            {
                handler = new EmptyAuthenticationHandler(delegatingHandler);
            }
            else
            {
                var identifier = serviceIdentifier ?? ((NameValueCollection)ConfigurationManager.GetSection("accenture.security.eso.service"))["Services:Identifier"];
                var authConfig = new AuthenticationConfiguration { RequireSsl = false, SetPrincipalOnRequestInstance = true };
                authConfig.AddMsftJsonWebToken(identifier);

                handler = new AuthenticationHandler(authConfig, delegatingHandler);
            }

            // Create the default odata route using regular conventions
            config.MapODataServiceRoute(
                         routeName: routeName,
                         routePrefix: routePrefix,
                         model: model,
                         pathHandler: new DefaultODataPathHandler(),
                         routingConventions: ODataRoutingConventions.CreateDefaultWithAttributeRouting(config, model),
                         defaultHandler: handler);
        }
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var authentication = new AuthenticationConfiguration 
            {
                ClaimsAuthenticationManager = new ClaimsTransformer(),
                RequireSsl = false,
                EnableSessionToken = true
            };

            #region Basic Authentication
            authentication.AddBasicAuthentication(UserCredentials.Validate);
            #endregion

            #region IdentityServer JWT
            //authentication.AddJsonWebToken(
            //    issuer: Constants.IdSrv.IssuerUri,
            //    audience: Constants.Audience,
            //    signingKey: Constants.IdSrv.SigningKey);

            authentication.AddMsftJsonWebToken(
                issuer: Constants.IdSrv.IssuerUri,
                audience: Constants.Audience,
                signingKey: Constants.IdSrv.SigningKey);
            #endregion

            #region Access Control Service JWT
            authentication.AddJsonWebToken(
                issuer: Constants.ACS.IssuerUri,
                audience: Constants.Audience,
                signingKey: Constants.ACS.SigningKey,
                scheme: Constants.ACS.Scheme);
            #endregion

            #region IdentityServer SAML
            authentication.AddSaml2(
                issuerThumbprint: Constants.IdSrv.SigningCertThumbprint,
                issuerName: Constants.IdSrv.IssuerUri,
                audienceUri: Constants.Realm,
                certificateValidator: X509CertificateValidator.None,
                options: AuthenticationOptions.ForAuthorizationHeader(Constants.IdSrv.SamlScheme),
                scheme: AuthenticationScheme.SchemeOnly(Constants.IdSrv.SamlScheme));
            #endregion

            #region Client Certificates
            authentication.AddClientCertificate(ClientCertificateMode.ChainValidation);
            #endregion

            return authentication;
        }
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var authentication = new AuthenticationConfiguration
            {
                RequireSsl = false,
            };

            authentication.AddJsonWebToken(
                issuer: Constants.AuthzSrv.IssuerName,
                audience: Constants.Audience,
                signingKey: Constants.AuthzSrv.SigningKey,
                claimMappings: ClaimMappings.None);

            return authentication;
        }
Ejemplo n.º 14
0
        private static void setBasicAuthentication(HttpConfiguration config)
        {
            var authConfig = new AuthenticationConfiguration
            {
                InheritHostClientIdentity = true,
                ClaimsAuthenticationManager = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager
            };

            var service=ObjectFactory.Container.GetInstance<IDeveloperService>();

            // setup authentication against membership
            authConfig.AddBasicAuthentication((userName, password) => service.CheckUserKey(userName,password));

            config.MessageHandlers.Add(new AuthenticationHandler(authConfig));
        }
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var authentication = new AuthenticationConfiguration
            {
                ClaimsAuthenticationManager = new ClaimsTransformer(),
                RequireSsl = false,
                EnableSessionToken = true
            };

            authentication.AddJsonWebToken(
                issuer: "http://identityserver.v2.thinktecture.com/trust/idsrv",
                audience: "https://localhost:44301/",
                signingKey: "8hlN4y8TZBYNLtUrhvLPUfLRjx3KWMo24JdAurlcRMs=");

            return authentication;
        }
Ejemplo n.º 16
0
        public static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var authentication = new AuthenticationConfiguration()
                {
                    ClaimsAuthenticationManager = new ClaimsTransformer(),
                    RequireSsl = false,
                    EnableSessionToken = true
                };

            authentication.AddJsonWebToken(
                issuer: "http://identityserver.v2.thinktecture.com/trust/idsrv",
                audience: "https://localhost:44308/",
                signingKey: "CBvAWq7BA9EncagGwAK2gTrEhs2IL20LiHIhFtxRIT4=");

            return authentication;
        }
        public static void Configure(HttpConfiguration config)
        {
            var authNConfig = new AuthenticationConfiguration();

            authNConfig.AddJsonWebToken(
                "http://identityserver.v2.thinktecture.com/trust/cw",
                "http://tt.com/mobile/todos",
                ConfigurationManager.AppSettings["oauthSigningKey"],
                AuthenticationOptions.ForAuthorizationHeader("Bearer"));

            authNConfig.ClaimsAuthenticationManager =
                FederatedAuthentication.FederationConfiguration
                    .IdentityConfiguration.ClaimsAuthenticationManager;

            config.MessageHandlers.Add(new AuthenticationHandler(authNConfig));
            config.Filters.Add(new ClaimsAuthorizeAttribute());
        }
Ejemplo n.º 18
0
        private void RegisterAuth(HttpConfiguration config)
        {
            // NOTE: You need to get into the ASP.NET Web API pipeline
            // in order to retrieve the session token.
            // e.g: GET /token should get you the token but instead you get 404.
            // but GET /api/token works as you are inside the ASP.NET Web API pipeline now.

            var auth = new AuthenticationConfiguration {
                // ClaimsAuthenticationManager = new ClaimsTransformer(),
                DefaultAuthenticationScheme = "Basic",
                EnableSessionToken = true // default lifetime is 10 hours
            };

            auth.AddBasicAuthentication(IsValid);
            var authHandler = new AuthenticationHandler(auth);
            config.MessageHandlers.Add(authHandler);
        }
Ejemplo n.º 19
0
        public static void AddBasicAuthentication(this AuthenticationConfiguration configuration, BasicAuthenticationSecurityTokenHandler.ValidateUserNameCredentialDelegate validationDelegate, AuthenticationOptions options, string realm = "localhost", bool retainPassword = false)
        {
            var handler = new BasicAuthenticationSecurityTokenHandler(validationDelegate)
            {
                RetainPassword = retainPassword
            };

            configuration.AddMapping(new AuthenticationOptionMapping
            {
                TokenHandler = new SecurityTokenHandlerCollection
                {
                    handler
                },
                Options = options,
                Scheme  = AuthenticationScheme.SchemeAndRealm("Basic", realm)
            });
        }
        public static void AddJsonWebToken(
            this AuthenticationConfiguration configuration,
            TokenValidationParameters validationParameters,
            AuthenticationOptions options,
            AuthenticationScheme scheme,
            Dictionary <string, string> claimMappings = null)
        {
            var handler = new JwtSecurityTokenHandlerWrapper(validationParameters, claimMappings);

            configuration.AddMapping(new AuthenticationOptionMapping
            {
                TokenHandler = new SecurityTokenHandlerCollection {
                    handler
                },
                Options = options,
                Scheme  = scheme
            });
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Configuration related to the Thinktecture Authorization Server
        /// </summary>
        /// <returns></returns>
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            /*ClaimsAuthenticationManager = new GridsClaimsAuthenticationManager(),*/

            var authentication = new AuthenticationConfiguration
            {
                RequireSsl = false,
            };

            authentication.AddJsonWebToken(

                issuer: Constants.AuthorizationServer.IssuerName,
                audience: Constants.Audience,
                signingKey: Constants.AuthorizationServer.SigningKey,
                claimMappings: ClaimMappings.None);

            return authentication;
        }
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            var authConfig = new AuthenticationConfiguration
            {
                InheritHostClientIdentity = true,
                ClaimsAuthenticationManager = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager
            };

            // setup authentication against membership
            authConfig.AddBasicAuthentication((userName, password) => Membership.ValidateUser(userName, password));
            
            config.MessageHandlers.Add(new AuthenticationHandler(authConfig));
        }
        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);
        }
        public static void Register(HttpConfiguration config)
        {
            var idsvrId = "http://idsrv.local/trust";
            var cert = X509.LocalMachine.TrustedPeople.SubjectDistinguishedName.Find("CN=sts", false).Single();
            
            {
                var authConfig = new AuthenticationConfiguration();
                authConfig.AddMsftJsonWebToken(
                    idsvrId,
                    "http://localhost/rp-adfs-webapi1",
                    cert);

                var authHandler = new AuthenticationHandler(authConfig, config);

                config.Routes.MapHttpRoute(
                    name: "test1",
                    routeTemplate: "api/test1",
                    defaults: new { controller = "Test1" },
                    constraints: null,
                    handler: authHandler
                );
            }

            {
                var authConfig = new AuthenticationConfiguration();
                authConfig.AddMsftJsonWebToken(
                    idsvrId,
                    "http://localhost/rp-adfs-webapi2",
                    cert);

                var authHandler = new AuthenticationHandler(authConfig, config);

                config.Routes.MapHttpRoute(
                    name: "test2",
                    routeTemplate: "api/test2",
                    defaults: new { controller="Test2" },
                    constraints: null,
                    handler: authHandler
                );
            }
        }
Ejemplo n.º 26
0
        public static void AddSaml2AndJwt(this AuthenticationConfiguration configuration, string issuerThumbprint, X509Certificate2 signingCertificate, string issuerName, string audienceUri, X509CertificateValidator certificateValidator, AuthenticationOptions options, AuthenticationScheme scheme, X509Certificate2 encryptionCertificate)
        {
            var validationParameters = new TokenValidationParameters()
            {
                AllowedAudience = audienceUri,
                SigningToken = new X509SecurityToken(signingCertificate),
                ValidIssuer = issuerName,
            };

            var jwtHandler = new JwtSecurityTokenHandlerWrapper(validationParameters);

            var samlHandlerConfig = CreateSaml2SecurityTokenHandlerConfiguration(issuerThumbprint, issuerName, audienceUri, certificateValidator, encryptionCertificate);
            var saml2Handler = new HttpSaml2SecurityTokenHandler() { Configuration = samlHandlerConfig };

            configuration.AddMapping(new AuthenticationOptionMapping
            {
                TokenHandler = new SecurityTokenHandlerCollection { jwtHandler, saml2Handler },
                Options = options,
                Scheme = scheme
            });
        }
Ejemplo n.º 27
0
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var options = new AuthenticationOptions()
            {
                RequestType = HttpRequestType.AuthorizationHeader,
                Scheme = "SAML"
            };

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

            var adfsConfig = new SecurityTokenHandlerConfiguration();
            adfsConfig.AudienceRestriction.AllowedAudienceUris.Add(new Uri("urn:claimsdemo:http45mvc"));
            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;
        }
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            var authentication = new AuthenticationConfiguration 
            {
                ClaimsAuthenticationManager = new ClaimsTransformer(),
                RequireSsl = false,
                EnableSessionToken = true
            };

            #region Basic Authentication
            authentication.AddBasicAuthentication((username, password) 
                => UserCredentials.Validate(username, password));
            #endregion

            #region IdentityServer JWT
            authentication.AddJsonWebToken(
                Constants.IdSrv.IssuerUri,
                Constants.Audience,
                Constants.IdSrv.SigningKey);
            #endregion

            #region Access Control Service JWT
            authentication.AddJsonWebToken(
                Constants.ACS.IssuerUri,
                Constants.Audience,
                Constants.ACS.SigningKey,
                AuthenticationOptions.ForAuthorizationHeader(Constants.ACS.Scheme));
            #endregion

            #region #IdentityServer SAML
            authentication.AddSaml2(
                issuerThumbprint: Constants.IdSrv.SigningCertThumbprint,
                issuerName: Constants.IdSrv.IssuerUri,
                audienceUri: Constants.Realm,
                certificateValidator: X509CertificateValidator.None,
                options: AuthenticationOptions.ForAuthorizationHeader(Constants.IdSrv.SamlScheme));
            #endregion

            return authentication;
        }
        internal static HttpServer Create(Func<HttpResponseMessage, string> normalizationCallback = null,
                                            Func<HttpRequestMessage, string, bool> verificationCallback = null)
        {
            var configuration = new HttpConfiguration();

            configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            Func<string, Credential> callback = (id) => Credentials.FirstOrDefault(c => c.Id == id);

            var authConfig = new AuthenticationConfiguration() { RequireSsl = false };
            authConfig.AddHawkAuthentication(callback, allowBewit: true,
                                                        normalizationCallback: normalizationCallback,
                                                            verificationCallback: verificationCallback);

            configuration.MessageHandlers.Add(new AuthenticationHandler(authConfig));

            return new HttpServer(configuration);
        }
Ejemplo n.º 30
0
        private static AuthenticationConfiguration CreateAuthenticationConfiguration()
        {
            const string signingKey = "fWUU28oBOIcaQuwUKiL01KztD/CsZX83C3I0M1MOYN4=";

            var confing = new SessionTokenConfiguration();
            confing.Scheme = "Session";
            confing.SigningKey = signingKey;

            var authentication = new AuthenticationConfiguration
            {
                RequireSsl = false,
                EnableSessionToken = true,
                SessionToken = confing,
            };

            authentication.DefaultAuthenticationScheme = "Basic";

            authentication.AddBasicAuthentication((username, password) => IsAuthenticated(username, password));
            
            //Use this to prevent your browser showing the standard basic auth login dialog on failure.
            authentication.SendWwwAuthenticateResponseHeader = false;
            
            return authentication;
        }
        public static AuthenticationConfiguration CreateConfiguration()
        {
            var config = new AuthenticationConfiguration
            {
                DefaultAuthenticationScheme = "Basic",
                EnableSessionToken = true
            };

            #region BasicAuthentication
            config.AddBasicAuthentication((userName, password) => userName == password, retainPassword: false);
            #endregion

            #region SimpleWebToken
            config.AddSimpleWebToken(
                issuer: "http://identity.thinktecture.com/trust",
                audience: Constants.Realm,
                signingKey: Constants.IdSrvSymmetricSigningKey,
                options: AuthenticationOptions.ForAuthorizationHeader("IdSrv"));
            #endregion

            #region JsonWebToken
            config.AddJsonWebToken(
                issuer: "http://selfissued.test",
                audience: Constants.Realm,
                signingKey: Constants.IdSrvSymmetricSigningKey,
                options: AuthenticationOptions.ForAuthorizationHeader("JWT"));
            #endregion

            #region IdentityServer SAML
            var idsrvRegistry = new ConfigurationBasedIssuerNameRegistry();
            idsrvRegistry.AddTrustedIssuer("A1EED7897E55388FCE60FEF1A1EED81FF1CBAEC6", "Thinktecture IdSrv");

            var idsrvConfig = new SecurityTokenHandlerConfiguration();
            idsrvConfig.AudienceRestriction.AllowedAudienceUris.Add(new Uri(Constants.Realm));
            idsrvConfig.IssuerNameRegistry = idsrvRegistry;
            idsrvConfig.CertificateValidator = X509CertificateValidator.None;

            config.AddSaml2(idsrvConfig, AuthenticationOptions.ForAuthorizationHeader("IdSrvSaml"));
            #endregion

            #region ADFS SAML
            var adfsRegistry = new ConfigurationBasedIssuerNameRegistry();
            adfsRegistry.AddTrustedIssuer("8EC7F962CC083FF7C5997D8A4D5ED64B12E4C174", "ADFS");
            adfsRegistry.AddTrustedIssuer("b6 93 46 34 7f 70 a9 c3 72 02 18 ae f1 82 2a 5c 97 b1 8c a5", "PETS ADFS");

            var adfsConfig = new SecurityTokenHandlerConfiguration();
            adfsConfig.AudienceRestriction.AllowedAudienceUris.Add(new Uri(Constants.Realm));
            adfsConfig.IssuerNameRegistry = adfsRegistry;
            adfsConfig.CertificateValidator = X509CertificateValidator.None;

            config.AddSaml2(adfsConfig, AuthenticationOptions.ForAuthorizationHeader("AdfsSaml"));
            #endregion

            #region ACS SWT
            config.AddSimpleWebToken(
                issuer: "https://" + Constants.ACS + "/",
                audience: Constants.Realm,
                signingKey: Constants.AcsSymmetricSigningKey,
                options: AuthenticationOptions.ForAuthorizationHeader("ACS"));
            #endregion

            #region AccessKey
            config.AddAccessKey(token =>
            {
                if (ObfuscatingComparer.IsEqual(token, "accesskey123"))
                {
                    return Principal.Create("Custom",
                        new Claim("customerid", "123"),
                        new Claim("email", "*****@*****.**"));
                }

                return null;
            }, AuthenticationOptions.ForQueryString("key"));
            #endregion

            #region Client Certificate
            config.AddClientCertificate(
                ClientCertificateMode.ChainValidationWithIssuerSubjectName, 
                "CN=PortableCA");
            #endregion

            return config;
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Create the configuration
 /// </summary>
 private static AuthenticationConfiguration CreateConfiguration()
 {
     AuthenticationConfiguration config = new AuthenticationConfiguration();
     config.AddBasicAuthentication(CheckAuthentication);
     return config;
 }
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpMessageHandler innerHandler)
 {
     _authN       = new HttpAuthentication(configuration);
     InnerHandler = innerHandler;
 }
 public HttpAuthentication(AuthenticationConfiguration configuration)
 {
     Configuration = configuration;
 }
Ejemplo n.º 35
0
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpMessageHandler innerHandler)
 {
     log.Info("Creando AuthenticationHandler2...");
     _authN       = new HttpAuthentication(configuration);
     InnerHandler = innerHandler;
 }
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpConfiguration httpConfiguration = null) : this(new HttpAuthentication(configuration), httpConfiguration)
 {
 }
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpMessageHandler innerHandler) : this(new HttpAuthentication(configuration), innerHandler)
 {
 }
Ejemplo n.º 38
0
 public HttpAuthentication(AuthenticationConfiguration configuration)
 {
     Configuration = configuration;
 }
Ejemplo n.º 39
0
        public static void AddSaml2(this AuthenticationConfiguration configuration, string issuerThumbprint, string issuerName, string audienceUri, X509CertificateValidator certificateValidator, AuthenticationOptions options, AuthenticationScheme scheme)
        {
            var handlerConfig = CreateSaml2SecurityTokenHandlerConfiguration(issuerThumbprint, issuerName, audienceUri, certificateValidator);

            configuration.AddSaml2(handlerConfig, options, scheme);
        }
 public AuthenticationHandler(AuthenticationConfiguration configuration, HttpMessageHandler innerHandler)
 {
     _authN = new HttpAuthentication(configuration);
     InnerHandler = innerHandler;
 }
 public OAuth2Handler(AuthenticationConfiguration configuration, HttpMessageHandler innerHandler)
     : this(new HttpAuthentication(configuration), innerHandler)
 {
 }