/// <summary> /// Return the SAML Settings to be used by the SAML Request /// and Response classes /// </summary> /// <returns></returns> public Saml.Settings SamlSettings() { Saml.Settings settings = new Saml.Settings(); settings.AssertionConsumerServiceUrl = ConsumeUrl(); settings.IdpSsoTargetUrl = IdpUrl(); settings.IdpCertificate = X509Certificate; settings.Issuer = MnoHelper.With(presetName).Api.Id; settings.NameIdentifierFormat = NameIdFormat; return(settings); }
/// <summary> /// Return the real Email if Maestrano.Sso.CreationMode is set /// to "real" and the VirtualEmail otherwise ("virtual" mode) /// </summary> public string ToEmail() { if (MnoHelper.With(presetName).Sso.CreationMode.Equals("real")) { return(Email); } else { return(VirtualEmail); } }
public void itSetsTheHostAndIdmProperlyIfDefined() { MnoHelper.With("sometenant").Environment = "production"; string expected = "https://somerandomhost.com"; MnoHelper.With("sometenant").App.Host = expected; MnoHelper.With("sometenant").Sso.Idm = expected; Assert.AreEqual(expected, MnoHelper.With("sometenant").App.Host); Assert.AreEqual(expected, MnoHelper.With("sometenant").Sso.Idm); }
public void Sso_ItBuildsTheRightSamlSettings() { MnoHelper.With("sometenant").Environment = "production"; MnoHelper.With("sometenant").Api.Id = "app-tenant1"; MnoHelper.With("sometenant").Sso.Idp = "https://idp.sometenantspecificendpoint.com"; MnoHelper.With("sometenant").Sso.Idm = "https://somespecificapphost.com"; MnoHelper.With("sometenant").Sso.ConsumePath = "/somespecifictenant/auth/saml/consume"; var samlSettings = MnoHelper.With("sometenant").Sso.SamlSettings(); Assert.AreEqual("app-tenant1", samlSettings.Issuer); Assert.AreEqual("https://idp.sometenantspecificendpoint.com/api/v1/auth/saml", samlSettings.IdpSsoTargetUrl); Assert.AreEqual("https://somespecificapphost.com/somespecifictenant/auth/saml/consume", samlSettings.AssertionConsumerServiceUrl); }
private static JsonClient Client(string presetName = "maestrano") { if (!clientDict.ContainsKey(presetName)) { var preset = MnoHelper.With(presetName); string host = preset.Api.Host; string path = preset.Api.Base; string key = preset.Api.Id; string secret = preset.Api.Key; var client = new JsonClient(host, path, key, secret); clientDict.Add(presetName, client); } return(clientDict[presetName]); }
/// <summary> /// Return a Client for a specific preset /// New scoped clients can be initialized with: Client.New("group-id", "preset") /// </summary> /// <param name="presetName"></param> /// <returns></returns> public static Client New(string groupId, string presetName = "maestrano") { if (presetName == null) { presetName = "maestrano"; } var preset = MnoHelper.With(presetName); var host = preset.Connec.Host; var path = preset.Connec.BasePath; var apiId = preset.Api.Id; var apiKey = preset.Api.Key; var connecScopedPath = path + "/" + groupId; return(new Client(host, connecScopedPath, apiId, apiKey)); }
public void itHasTheRightDefaultTestConfig() { MnoHelper.ClearPreset("sometenant"); MnoHelper.Environment = "development"; // App Assert.AreEqual("http://myapp.com", MnoHelper.With("sometenant").App.Host); // API Assert.AreEqual("http://api-sandbox.maestrano.io", MnoHelper.With("sometenant").Api.Host); Assert.AreEqual("/api/v1/", MnoHelper.With("sometenant").Api.Base); Assert.AreEqual("C#", MnoHelper.With("sometenant").Api.Lang); Assert.AreEqual(MnoHelper.Version, MnoHelper.With("sometenant").Api.Version); Assert.AreEqual(Environment.OSVersion.ToString() + " - " + Environment.Version.ToString(), MnoHelper.With("sometenant").Api.LangVersion); // SSO Assert.IsTrue(MnoHelper.With("sometenant").Sso.Enabled); Assert.IsTrue(MnoHelper.With("sometenant").Sso.SloEnabled); Assert.AreEqual("https://idp.sometenant.com", MnoHelper.With("sometenant").Sso.Idp); Assert.AreEqual("https://idm.myapp.com", MnoHelper.With("sometenant").Sso.Idm); Assert.AreEqual("virtual", MnoHelper.With("sometenant").Sso.CreationMode); Assert.AreEqual("/sometenant/auth/saml/init.aspx", MnoHelper.With("sometenant").Sso.InitPath); Assert.AreEqual("/sometenant/auth/saml/consume", MnoHelper.With("sometenant").Sso.ConsumePath); Assert.AreEqual("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent", MnoHelper.With("sometenant").Sso.NameIdFormat); Assert.AreEqual("01:06:15:89:25:7d:78:12:28:a6:69:c7:de:63:ed:74:21:f9:f5:36", MnoHelper.With("someten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BAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCc\nMPgV0CpumKRMulOeZwdpnyLQI/NTr3VVHhDDxxCzcB0zlZ2xyDACGnIG2cQJJxfc\n2GcsFnb0BMw48K6TEhAaV92Q7bt1/TYRvprvhxUNMX2N8PHaYELFG2nWfQ4vqxES\nRkjkjqy+H7vir/MOF3rlFjiv5twAbDKYHXDT7v1YCg==\n-----END CERTIFICATE-----", MnoHelper.With("sometenant").Sso.X509Certificate); // Connec Assert.AreEqual("http://api-sandbox.maestrano.io", MnoHelper.With("sometenant").Connec.Host); Assert.AreEqual("/connec/api/v2", MnoHelper.With("sometenant").Connec.BasePath); // Webhook Assert.AreEqual("/maestrano/account/groups/:id", MnoHelper.With("sometenant").Webhook.Account.GroupsPath); Assert.AreEqual("/maestrano/account/groups/:group_id/users/:id", MnoHelper.With("sometenant").Webhook.Account.GroupUsersPath); Assert.AreEqual("/maestrano/connec/notifications", MnoHelper.With("sometenant").Webhook.Connec.NotificationsPath); // Webhook - Connec! Subscriptions Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Accounts); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Company); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Invoices); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Items); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Organizations); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Payments); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.People); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.TaxCodes); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.TaxRates); }
public void itHasTheRightDefaultTestConfig() { MnoHelper.ClearPreset("sometenant"); MnoHelper.With("sometenant").Environment = "development"; // App Assert.AreEqual("http://myapp.com", MnoHelper.With("sometenant").App.Host); // API Assert.AreEqual("http://api-sandbox.maestrano.io", MnoHelper.With("sometenant").Api.Host); Assert.AreEqual("/api/v1/", MnoHelper.With("sometenant").Api.Base); Assert.AreEqual("C#", MnoHelper.With("sometenant").Api.Lang); Assert.AreEqual(MnoHelper.Version, MnoHelper.With("sometenant").Api.Version); Assert.AreEqual(Environment.OSVersion.ToString() + " - " + Environment.Version.ToString(), MnoHelper.With("sometenant").Api.LangVersion); // SSO Assert.IsTrue(MnoHelper.With("sometenant").Sso.Enabled); Assert.IsTrue(MnoHelper.With("sometenant").Sso.SloEnabled); Assert.AreEqual("https://idp.sometenant.com", MnoHelper.With("sometenant").Sso.Idp); Assert.AreEqual("https://idm.myapp.com", MnoHelper.With("sometenant").Sso.Idm); Assert.AreEqual("virtual", MnoHelper.With("sometenant").Sso.CreationMode); Assert.AreEqual("/sometenant/auth/saml/init.aspx", MnoHelper.With("sometenant").Sso.InitPath); Assert.AreEqual("/sometenant/auth/saml/consume", MnoHelper.With("sometenant").Sso.ConsumePath); Assert.AreEqual("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent", MnoHelper.With("sometenant").Sso.NameIdFormat); // Connec Assert.AreEqual("http://api-sandbox.maestrano.io", MnoHelper.With("sometenant").Connec.Host); Assert.AreEqual("/connec/api/v2", MnoHelper.With("sometenant").Connec.BasePath); // Webhook Assert.AreEqual("/maestrano/account/groups/:id", MnoHelper.With("sometenant").Webhook.Account.GroupsPath); Assert.AreEqual("/maestrano/account/groups/:group_id/users/:id", MnoHelper.With("sometenant").Webhook.Account.GroupUsersPath); Assert.AreEqual("/maestrano/connec/notifications", MnoHelper.With("sometenant").Webhook.Connec.NotificationsPath); // Webhook - Connec! Subscriptions Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Accounts); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Company); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Invoices); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Items); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Organizations); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.Payments); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.People); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.TaxCodes); Assert.IsFalse(MnoHelper.With("sometenant").Webhook.Connec.Subscriptions.TaxRates); }
private static RestClient Client(string presetName = "maestrano") { if (!clientDict.ContainsKey(presetName)) { var client = new RestClient(); // silverlight friendly way to get current version var assembly = Assembly.GetExecutingAssembly(); AssemblyName assemblyName = new AssemblyName(assembly.FullName); var version = assemblyName.Version; client = new RestClient(); client.UserAgent = "maestrano-dotnet/" + version; client.Authenticator = new HttpBasicAuthenticator(MnoHelper.With(presetName).Api.Id, MnoHelper.With(presetName).Api.Key); client.BaseUrl = String.Format("{0}{1}", MnoHelper.With(presetName).Api.Host, MnoHelper.With(presetName).Api.Base); clientDict.Add(presetName, client); } return(clientDict[presetName]); }
public void itSetsTheX509CertificateProperly() { MnoHelper.ClearPreset("sometenant"); MnoHelper.Environment = "production"; MnoHelper.With("sometenant").Environment = "development"; Assert.AreEqual("01:06:15:89:25:7d:78:12:28:a6:69:c7:de:63:ed:74:21:f9:f5:36", MnoHelper.With("sometenant").Sso.X509Fingerprint); Assert.AreEqual("-----BEGIN CERTIFICATE-----\nMIIDezCCAuSgAwIBAgIJAOehBr+YIrhjMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\nVQQGEwJBVTEMMAoGA1UECBMDTlNXMQ8wDQYDVQQHEwZTeWRuZXkxGjAYBgNVBAoT\nEU1hZXN0cmFubyBQdHkgTHRkMRYwFAYDVQQDEw1tYWVzdHJhbm8uY29tMSQwIgYJ\nKoZIhvcNAQkBFhVzdXBwb3J0QG1hZXN0cmFuby5jb20wHhcNMTQwMTA0MDUyMjM5\nWhcNMzMxMjMwMDUyMjM5WjCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEP\nMA0GA1UEBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQG\nA1UEAxMNbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVz\ndHJhbm8uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVkIqo5t5Paflu\nP2zbSbzxn29n6HxKnTcsubycLBEs0jkTkdG7seF1LPqnXl8jFM9NGPiBFkiaR15I\n5w482IW6mC7s8T2CbZEL3qqQEAzztEPnxQg0twswyIZWNyuHYzf9fw0AnohBhGu2\n28EZWaezzT2F333FOVGSsTn1+u6tFwIDAQABo4HuMIHrMB0GA1UdDgQWBBSvrNxo\neHDm9nhKnkdpe0lZjYD1GzCBuwYDVR0jBIGzMIGwgBSvrNxoeHDm9nhKnkdpe0lZ\njYD1G6GBjKSBiTCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEPMA0GA1UE\nBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQGA1UEAxMN\nbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVzdHJhbm8u\nY29tggkA56EGv5giuGMwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCc\nMPgV0CpumKRMulOeZwdpnyLQI/NTr3VVHhDDxxCzcB0zlZ2xyDACGnIG2cQJJxfc\n2GcsFnb0BMw48K6TEhAaV92Q7bt1/TYRvprvhxUNMX2N8PHaYELFG2nWfQ4vqxES\nRkjkjqy+H7vir/MOF3rlFjiv5twAbDKYHXDT7v1YCg==\n-----END CERTIFICATE-----", MnoHelper.With("sometenant").Sso.X509Certificate); }
/// <summary> /// Return wether the session is valid or not. Perform /// remote check to maestrano if recheck is overdue. /// </summary> /// <param name="ifSession">If set to true then session return false ONLY if maestrano session exists and is invalid</param> /// <returns></returns> public Boolean IsValid(Boolean ifSession = false) { var client = new RestClient(MnoHelper.With(presetName).Sso.Idp); return(IsValid(client, ifSession)); }
/// <summary> /// Check whether the remote maestrano session is still /// valid /// </summary> /// <returns></returns> public Boolean PerformRemoteCheck() { var client = new RestClient(MnoHelper.With(presetName).Sso.Idp); return(PerformRemoteCheck(client)); }
/// <summary> /// return the Maestrano logout url to be used for redirecting a user after logout /// </summary> public string LogoutUrl() { return(MnoHelper.With(presetName).Sso.LogoutUrl(this.Uid)); }