public static void AddAccessKey(this AuthenticationConfiguration configuration, SimpleSecurityTokenHandler.ValidateTokenDelegate validateTokenDelegate, AuthenticationOptions options) { configuration.AddMapping(new AuthenticationOptionMapping { TokenHandler = new SecurityTokenHandlerCollection { new SimpleSecurityTokenHandler(validateTokenDelegate) }, Options = options }); }
public void AddAccessKey(SimpleSecurityTokenHandler handler, AuthenticationOptions options) { AddMapping(new AuthenticationOptionMapping { TokenHandler = new SecurityTokenHandlerCollection { handler }, Options = options }); }
public static void AddAccessKey(this AuthenticationConfiguration configuration, SimpleSecurityTokenHandler handler, AuthenticationOptions options) { configuration.AddMapping(new AuthenticationOptionMapping { TokenHandler = new SecurityTokenHandlerCollection { handler }, Options = options }); }
public void AddAccessKey(SimpleSecurityTokenHandler.ValidateTokenDelegate validateTokenDelegate, AuthenticationOptions options) { AddMapping(new AuthenticationOptionMapping { TokenHandler = new SecurityTokenHandlerCollection { new SimpleSecurityTokenHandler("", validateTokenDelegate) }, Options = options }); }
public void Ctor_SecurityToken_Works() { var securityToken = new UserNameSecurityToken(user, password); var securityTokenHandler = new SimpleSecurityTokenHandler(); BootstrapContext bootstrapContext = new BootstrapContext(securityToken, securityTokenHandler); Assert.IsNotNull(bootstrapContext.SecurityToken, "#1"); Assert.AreEqual(user, securityToken.UserName, "#2"); Assert.AreEqual(password, securityToken.Password, "#3"); Assert.AreEqual(securityTokenHandler, bootstrapContext.SecurityTokenHandler, "#4"); Assert.IsNull(bootstrapContext.Token, "#5"); Assert.IsNull(bootstrapContext.TokenBytes, "#6"); }
public void Serialize_SecurityTokenAndHandler_Works() { var securityToken = new UserNameSecurityToken(user, password, "uuid-927c0b98-ba18-49d2-a653-306d60f85751-3"); var securityTokenHandler = new SimpleSecurityTokenHandler(); BootstrapContext bootstrapContext = new BootstrapContext(securityToken, securityTokenHandler); BinaryFormatter binaryFormatter = new BinaryFormatter(); using (var s = new MemoryStream()) { binaryFormatter.Serialize(s, bootstrapContext); s.Position = 0; BootstrapContext bootstrapContext2 = binaryFormatter.Deserialize(s) as BootstrapContext; Assert.IsNotNull(bootstrapContext2, "#1"); // Deserialize does not restore the SecurityToken, but restores into the Token. Assert.IsNotNull(bootstrapContext2.Token, "#3"); // We replace ' /' by '/' to accomodate the xml writer differences between mono and .net Assert.AreEqual(SerializedBootstrapContextSecurityTokenString.Replace(" /", "/"), bootstrapContext2.Token.Replace(" /", "/"), "#2"); Assert.AreEqual(bootstrapContext.TokenBytes, bootstrapContext2.TokenBytes, "#3"); Assert.IsNull(bootstrapContext2.SecurityToken, "#4"); Assert.IsNull(bootstrapContext2.SecurityTokenHandler, "#5"); } }
public static void AddAccessKey(this AuthenticationConfiguration configuration, SimpleSecurityTokenHandler handler, AuthenticationOptions options) { configuration.AddMapping(new AuthenticationOptionMapping { TokenHandler = new SecurityTokenHandlerCollection { handler }, Options = options, }); }
public static AuthenticationConfiguration CreateConfiguration() { var config = new AuthenticationConfiguration { DefaultAuthenticationScheme = "Basic", }; #region Basic Authentication config.AddBasicAuthentication((userName, password) => userName == password); #endregion #region SimpleWebToken config.AddSimpleWebToken( "http://identity.thinktecture.com/trust", Constants.Realm, Constants.IdSrvSymmetricSigningKey, AuthenticationOptions.ForAuthorizationHeader("IdSrv")); #endregion #region JsonWebToken config.AddJsonWebToken( "http://selfissued.test", Constants.Realm, Constants.IdSrvSymmetricSigningKey, 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 ACS SWT config.AddSimpleWebToken( "https://" + Constants.ACS + "/", Constants.Realm, Constants.AcsSymmetricSigningKey, AuthenticationOptions.ForAuthorizationHeader("ACS")); #endregion #region AccessKey var handler = new SimpleSecurityTokenHandler("my access key", token => { if (ObfuscatingComparer.IsEqual(token, "accesskey123")) { return(new ClaimsIdentity(new Claim[] { new Claim("customerid", "123") }, "Custom")); } return(null); }); config.AddAccessKey(handler, AuthenticationOptions.ForQueryString("key")); #endregion return(config); }
public void Serialize_SecurityTokenAndHandler_Works () { var securityToken = new UserNameSecurityToken (user, password, "uuid-927c0b98-ba18-49d2-a653-306d60f85751-3"); var securityTokenHandler = new SimpleSecurityTokenHandler (); BootstrapContext bootstrapContext = new BootstrapContext (securityToken, securityTokenHandler); BinaryFormatter binaryFormatter = new BinaryFormatter (); using (var s = new MemoryStream ()) { binaryFormatter.Serialize (s, bootstrapContext); s.Position = 0; BootstrapContext bootstrapContext2 = binaryFormatter.Deserialize (s) as BootstrapContext; Assert.IsNotNull (bootstrapContext2, "#1"); // Deserialize does not restore the SecurityToken, but restores into the Token. Assert.IsNotNull (bootstrapContext2.Token, "#3"); // We replace ' /' by '/' to accomodate the xml writer differences between mono and .net Assert.AreEqual (SerializedBootstrapContextSecurityTokenString.Replace (" /", "/"), bootstrapContext2.Token.Replace (" /", "/"), "#2"); Assert.AreEqual (bootstrapContext.TokenBytes, bootstrapContext2.TokenBytes, "#3"); Assert.IsNull (bootstrapContext2.SecurityToken, "#4"); Assert.IsNull (bootstrapContext2.SecurityTokenHandler, "#5"); } }
public void Ctor_SecurityToken_Works () { var securityToken = new UserNameSecurityToken (user, password); var securityTokenHandler = new SimpleSecurityTokenHandler (); BootstrapContext bootstrapContext = new BootstrapContext (securityToken, securityTokenHandler); Assert.IsNotNull (bootstrapContext.SecurityToken, "#1"); Assert.AreEqual (user, securityToken.UserName, "#2"); Assert.AreEqual (password, securityToken.Password, "#3"); Assert.AreEqual (securityTokenHandler, bootstrapContext.SecurityTokenHandler, "#4"); Assert.IsNull (bootstrapContext.Token, "#5"); Assert.IsNull (bootstrapContext.TokenBytes, "#6"); }