public async Task UpdateConfigMinimal(ProviderTestConfig config) { var handler = new MockMessageHandler() { Response = SamlProviderConfigResponse, }; var auth = config.CreateAuth(handler); var args = new SamlProviderConfigArgs() { ProviderId = "saml.minimal-provider", IdpEntityId = "IDP_ENTITY_ID", }; var provider = await auth.UpdateProviderConfigAsync(args); this.AssertSamlProviderConfig(provider); var request = Assert.Single(handler.Requests); Assert.Equal(ProviderTestConfig.PatchMethod, request.Method); config.AssertRequest( "inboundSamlConfigs/saml.minimal-provider?updateMask=idpConfig.idpEntityId", request); var body = NewtonsoftJsonSerializer.Instance.Deserialize <JObject>( handler.LastRequestBody); Assert.Single(body); var idpConfig = (JObject)body["idpConfig"]; Assert.Equal("IDP_ENTITY_ID", idpConfig["idpEntityId"]); }
public async Task UpdateConfigNotFoundError(ProviderTestConfig config) { var handler = new MockMessageHandler() { StatusCode = HttpStatusCode.NotFound, Response = ProviderTestConfig.ConfigNotFoundResponse, }; var auth = config.CreateAuth(handler); var args = new SamlProviderConfigArgs() { ProviderId = "saml.provider", IdpEntityId = "IDP_ENTITY_ID", }; var exception = await Assert.ThrowsAsync <FirebaseAuthException>( () => auth.UpdateProviderConfigAsync(args)); Assert.Equal(ErrorCode.NotFound, exception.ErrorCode); Assert.Equal(AuthErrorCode.ConfigurationNotFound, exception.AuthErrorCode); Assert.Equal( "No identity provider configuration found for the given identifier " + "(CONFIGURATION_NOT_FOUND).", exception.Message); Assert.NotNull(exception.HttpResponse); Assert.Null(exception.InnerException); }
public async Task UpdateProviderConfig() { var args = new SamlProviderConfigArgs() { ProviderId = this.providerId, DisplayName = "UPDATED_SAML_DISPLAY_NAME", Enabled = false, IdpEntityId = "UPDATED_IDP_ENTITY_ID", SsoUrl = "https://example.com/updated-login", X509Certificates = new List <string> { SamlProviderConfigFixture <T> .X509Certificates[1], }, RpEntityId = "UPDATED_RP_ENTITY_ID", CallbackUrl = "https://projectId.firebaseapp.com/__/auth/updated-handler", }; var config = await this.auth.UpdateProviderConfigAsync(args); Assert.Equal(this.providerId, config.ProviderId); Assert.Equal("UPDATED_SAML_DISPLAY_NAME", config.DisplayName); Assert.False(config.Enabled); Assert.Equal("UPDATED_IDP_ENTITY_ID", config.IdpEntityId); Assert.Equal("https://example.com/updated-login", config.SsoUrl); Assert.Single(config.X509Certificates, SamlProviderConfigFixture <T> .X509Certificates[1]); Assert.Equal("UPDATED_RP_ENTITY_ID", config.RpEntityId); Assert.Equal( "https://projectId.firebaseapp.com/__/auth/updated-handler", config.CallbackUrl); }
public async Task CreateConfigUnknownError(ProviderTestConfig config) { var handler = new MockMessageHandler() { StatusCode = HttpStatusCode.InternalServerError, Response = ProviderTestConfig.UnknownErrorResponse, }; var auth = config.CreateAuth(handler); var args = new SamlProviderConfigArgs() { ProviderId = "saml.minimal-provider", IdpEntityId = "IDP_ENTITY_ID", SsoUrl = "https://example.com/login", X509Certificates = new List <string>() { "CERT1", "CERT2" }, RpEntityId = "RP_ENTITY_ID", CallbackUrl = "https://projectId.firebaseapp.com/__/auth/handler", }; var exception = await Assert.ThrowsAsync <FirebaseAuthException>( () => auth.CreateProviderConfigAsync(args)); Assert.Equal(ErrorCode.Internal, exception.ErrorCode); Assert.Null(exception.AuthErrorCode); Assert.StartsWith( "Unexpected HTTP response with status: 500 (InternalServerError)", exception.Message); Assert.NotNull(exception.HttpResponse); Assert.Null(exception.InnerException); }
public async Task UpdateConfigMinimal() { var handler = new MockMessageHandler() { Response = SamlProviderConfigResponse, }; var auth = ProviderConfigTestUtils.CreateFirebaseAuth(handler); var args = new SamlProviderConfigArgs() { ProviderId = "saml.minimal-provider", IdpEntityId = "IDP_ENTITY_ID", }; var provider = await auth.UpdateProviderConfigAsync(args); this.AssertSamlProviderConfig(provider); Assert.Equal(1, handler.Requests.Count); var request = handler.Requests[0]; Assert.Equal(ProviderConfigTestUtils.PatchMethod, request.Method); Assert.Equal( "/v2/projects/project1/inboundSamlConfigs/saml.minimal-provider?updateMask=idpConfig.idpEntityId", request.Url.PathAndQuery); ProviderConfigTestUtils.AssertClientVersionHeader(request); var body = NewtonsoftJsonSerializer.Instance.Deserialize <JObject>( handler.LastRequestBody); Assert.Single(body); var idpConfig = (JObject)body["idpConfig"]; Assert.Equal("IDP_ENTITY_ID", idpConfig["idpEntityId"]); }
public async Task UpdateConfigInvalidArgs(SamlProviderConfigArgs args, string expected) { var auth = ProviderConfigTestUtils.CreateFirebaseAuth(); var exception = await Assert.ThrowsAsync <ArgumentException>( () => auth.UpdateProviderConfigAsync(args)); Assert.Equal(expected, exception.Message); }
public async Task CreateConfigInvalidArgs( ProviderTestConfig config, SamlProviderConfigArgs args, string expected) { var auth = config.CreateAuth(); var exception = await Assert.ThrowsAsync <ArgumentException>( () => auth.CreateProviderConfigAsync(args)); Assert.Equal(expected, exception.Message); }
public async Task UpdateConfig() { var handler = new MockMessageHandler() { Response = SamlProviderConfigResponse, }; var auth = ProviderConfigTestUtils.CreateFirebaseAuth(handler); var args = new SamlProviderConfigArgs() { ProviderId = "saml.provider", DisplayName = "samlProviderName", Enabled = true, IdpEntityId = "IDP_ENTITY_ID", SsoUrl = "https://example.com/login", X509Certificates = new List <string>() { "CERT1", "CERT2" }, RpEntityId = "RP_ENTITY_ID", CallbackUrl = "https://projectId.firebaseapp.com/__/auth/handler", }; var provider = await auth.UpdateProviderConfigAsync(args); this.AssertSamlProviderConfig(provider); Assert.Equal(1, handler.Requests.Count); var request = handler.Requests[0]; Assert.Equal(ProviderConfigTestUtils.PatchMethod, request.Method); var mask = "displayName,enabled,idpConfig.idpCertificates,idpConfig.idpEntityId,idpConfig.ssoUrl," + "spConfig.callbackUri,spConfig.spEntityId"; Assert.Equal( $"/v2/projects/project1/inboundSamlConfigs/saml.provider?updateMask={mask}", request.Url.PathAndQuery); ProviderConfigTestUtils.AssertClientVersionHeader(request); var body = NewtonsoftJsonSerializer.Instance.Deserialize <JObject>( handler.LastRequestBody); Assert.Equal(4, body.Count); Assert.Equal("samlProviderName", body["displayName"]); Assert.True((bool)body["enabled"]); this.AssertIdpConfig((JObject)body["idpConfig"]); this.AssertSpConfig((JObject)body["spConfig"]); }
internal static async Task UpdateSamlProviderConfig() { // [START update_saml_provider] var args = new SamlProviderConfigArgs() { ProviderId = "saml.myProvider", X509Certificates = new List <string>() { "-----BEGIN CERTIFICATE-----\nCERT2...\n-----END CERTIFICATE-----", "-----BEGIN CERTIFICATE-----\nCERT3...\n-----END CERTIFICATE-----", }, }; SamlProviderConfig saml = await FirebaseAuth.DefaultInstance .UpdateProviderConfigAsync(args); Console.WriteLine($"Updated SAML provider: {saml.ProviderId}"); // [END update_saml_provider] }
public SamlProviderConfigFixture() { var providerId = $"saml.{AuthIntegrationUtils.GetRandomIdentifier()}"; var args = new SamlProviderConfigArgs { ProviderId = providerId, DisplayName = "SAML_DISPLAY_NAME", Enabled = true, IdpEntityId = "IDP_ENTITY_ID", SsoUrl = "https://example.com/login", X509Certificates = new List <string> { X509Certificates[0] }, RpEntityId = "RP_ENTITY_ID", CallbackUrl = "https://projectId.firebaseapp.com/__/auth/handler", }; this.ProviderConfig = this.Auth.CreateProviderConfigAsync(args).Result; }
public async Task CreateConfig(ProviderTestConfig config) { var handler = new MockMessageHandler() { Response = SamlProviderConfigResponse, }; var auth = config.CreateAuth(handler); var args = new SamlProviderConfigArgs() { ProviderId = "saml.provider", DisplayName = "samlProviderName", Enabled = true, IdpEntityId = "IDP_ENTITY_ID", SsoUrl = "https://example.com/login", X509Certificates = new List <string>() { "CERT1", "CERT2" }, RpEntityId = "RP_ENTITY_ID", CallbackUrl = "https://projectId.firebaseapp.com/__/auth/handler", }; var provider = await auth.CreateProviderConfigAsync(args); this.AssertSamlProviderConfig(provider); var request = Assert.Single(handler.Requests); Assert.Equal(HttpMethod.Post, request.Method); config.AssertRequest("inboundSamlConfigs?inboundSamlConfigId=saml.provider", request); var body = NewtonsoftJsonSerializer.Instance.Deserialize <JObject>( handler.LastRequestBody); Assert.Equal(4, body.Count); Assert.Equal("samlProviderName", body["displayName"]); Assert.True((bool)body["enabled"]); this.AssertIdpConfig((JObject)body["idpConfig"]); this.AssertSpConfig((JObject)body["spConfig"]); }
public async Task CreateConfigMinimal() { var handler = new MockMessageHandler() { Response = SamlProviderConfigResponse, }; var auth = ProviderConfigTestUtils.CreateFirebaseAuth(handler); var args = new SamlProviderConfigArgs() { ProviderId = "saml.minimal-provider", IdpEntityId = "IDP_ENTITY_ID", SsoUrl = "https://example.com/login", X509Certificates = new List <string>() { "CERT1", "CERT2" }, RpEntityId = "RP_ENTITY_ID", CallbackUrl = "https://projectId.firebaseapp.com/__/auth/handler", }; var provider = await auth.CreateProviderConfigAsync(args); this.AssertSamlProviderConfig(provider); Assert.Equal(1, handler.Requests.Count); var request = handler.Requests[0]; Assert.Equal(HttpMethod.Post, request.Method); Assert.Equal( "/v2/projects/project1/inboundSamlConfigs?inboundSamlConfigId=saml.minimal-provider", request.Url.PathAndQuery); ProviderConfigTestUtils.AssertClientVersionHeader(request); var body = NewtonsoftJsonSerializer.Instance.Deserialize <JObject>( handler.LastRequestBody); Assert.Equal(2, body.Count); this.AssertIdpConfig((JObject)body["idpConfig"]); this.AssertSpConfig((JObject)body["spConfig"]); }
internal static async Task CreateSamlProviderConfig() { // [START create_saml_provider] var args = new SamlProviderConfigArgs() { DisplayName = "SAML provider name", Enabled = true, ProviderId = "saml.myProvider", IdpEntityId = "IDP_ENTITY_ID", SsoUrl = "https://example.com/saml/sso/1234/", X509Certificates = new List <string>() { "-----BEGIN CERTIFICATE-----\nCERT1...\n-----END CERTIFICATE-----", "-----BEGIN CERTIFICATE-----\nCERT2...\n-----END CERTIFICATE-----", }, RpEntityId = "RP_ENTITY_ID", CallbackUrl = "https://project-id.firebaseapp.com/__/auth/handler", }; SamlProviderConfig saml = await FirebaseAuth.DefaultInstance .CreateProviderConfigAsync(args); Console.WriteLine($"Created new SAML provider: {saml.ProviderId}"); // [END create_saml_provider] }