internal ListTenantsRequest( string baseUrl, ListTenantsOptions options, ErrorHandlingHttpClient <FirebaseAuthException> httpClient) : base(baseUrl, options?.PageToken, options?.PageSize, httpClient) { }
public FirebaseMessagingClient( HttpClientFactory clientFactory, GoogleCredential credential, string projectId) { if (string.IsNullOrEmpty(projectId)) { throw new ArgumentException( "Project ID is required to access messaging service. Use a service account " + "credential or set the project ID explicitly via AppOptions. Alternatively " + "you can set the project ID via the GOOGLE_CLOUD_PROJECT environment " + "variable."); } this.httpClient = new ErrorHandlingHttpClient <FirebaseMessagingException>( new ErrorHandlingHttpClientArgs <FirebaseMessagingException>() { HttpClientFactory = clientFactory.ThrowIfNull(nameof(clientFactory)), Credential = credential.ThrowIfNull(nameof(credential)), RequestExceptionHandler = MessagingErrorHandler.Instance, ErrorResponseHandler = MessagingErrorHandler.Instance, DeserializeExceptionHandler = MessagingErrorHandler.Instance, }); this.fcmClientService = new FCMClientService(new BaseClientService.Initializer() { HttpClientFactory = clientFactory, HttpClientInitializer = credential, }); this.sendUrl = string.Format(FcmSendUrl, projectId); this.restPath = this.sendUrl.Substring(FcmBaseUrl.Length); }
internal ApiClient( string projectId, string tenantId, ErrorHandlingHttpClientArgs <FirebaseAuthException> args) { if (string.IsNullOrEmpty(projectId)) { throw new ArgumentException( "Must initialize FirebaseApp with a project ID to manage provider" + " configurations."); } var baseUrl = string.Format(IdToolkitUrl, projectId); if (tenantId != null) { this.BaseUrl = $"{baseUrl}/tenants/{tenantId}"; } else { this.BaseUrl = baseUrl; } this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>(args); }
private ListUsersRequest( string baseUrl, ErrorHandlingHttpClient <FirebaseAuthException> httpClient, ListUsersOptions options) { this.baseUrl = baseUrl; this.httpClient = httpClient; this.RequestParameters = new Dictionary <string, IParameter>(); this.SetPageSize(options.PageSize); this.SetPageToken(options.PageToken); }
/// <summary> /// Initializes a new instance of the <see cref="InstanceIdClient"/> class. /// </summary> /// <param name="clientFactory">A default implentation of the HTTP client factory.</param> /// <param name="credential">An instance of the <see cref="GoogleCredential"/> class.</param> public InstanceIdClient(HttpClientFactory clientFactory, GoogleCredential credential) { this.httpClient = new ErrorHandlingHttpClient <FirebaseMessagingException>( new ErrorHandlingHttpClientArgs <FirebaseMessagingException>() { HttpClientFactory = clientFactory.ThrowIfNull(nameof(clientFactory)), Credential = credential.ThrowIfNull(nameof(credential)), RequestExceptionHandler = MessagingErrorHandler.Instance, ErrorResponseHandler = MessagingErrorHandler.Instance, DeserializeExceptionHandler = MessagingErrorHandler.Instance, }); }
internal ApiClient( string projectId, ErrorHandlingHttpClientArgs <FirebaseAuthException> args) { if (string.IsNullOrEmpty(projectId)) { throw new ArgumentException( "Must initialize FirebaseApp with a project ID to manage provider" + " configurations."); } this.baseUrl = string.Format(IdToolkitUrl, projectId); this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>(args); }
internal Factory( string baseUrl, ErrorHandlingHttpClient <FirebaseAuthException> httpClient, ListUsersOptions options = null) { this.baseUrl = baseUrl; this.httpClient = httpClient; this.options = new ListUsersOptions() { PageSize = CheckPageSize(options?.PageSize), PageToken = CheckPageToken(options?.PageToken), }; }
internal TenantManager(Args args) { if (string.IsNullOrEmpty(args.ProjectId)) { throw new ArgumentException( "Must initialize FirebaseApp with a project ID to manage tenants."); } this.app = args.App; this.baseUrl = string.Format(IdToolkitUrl, args.ProjectId); this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>( args.ToHttpClientArgs()); }
public IAMSigner(HttpClientFactory clientFactory, GoogleCredential credential) { this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>( new ErrorHandlingHttpClientArgs <FirebaseAuthException>() { HttpClientFactory = clientFactory, ErrorResponseHandler = IAMSignerErrorHandler.Instance, RequestExceptionHandler = AuthErrorHandler.Instance, DeserializeExceptionHandler = AuthErrorHandler.Instance, }); this.keyId = new Lazy <Task <string> >( async() => await DiscoverServiceAccountIdAsync(clientFactory) .ConfigureAwait(false), true); }
public async Task Dispose() { var handler = new MockMessageHandler() { Response = @"{}", }; var factory = new MockHttpClientFactory(handler); var httpClient = new ErrorHandlingHttpClient <FirebaseException>( this.CreateArgs(factory)); httpClient.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await httpClient.SendAndDeserializeAsync <Dictionary <string, string> >( this.CreateRequest())); }
public async Task NetworkError() { var handler = new MockMessageHandler() { Exception = new HttpRequestException("Low-level network error"), }; var factory = new MockHttpClientFactory(handler); var httpClient = new ErrorHandlingHttpClient <FirebaseException>( this.CreateArgs(factory)); var exception = await Assert.ThrowsAsync <FirebaseException>( async() => await httpClient.SendAndDeserializeAsync <Dictionary <string, string> >( this.CreateRequest())); Assert.Equal(ErrorCode.Unknown, exception.ErrorCode); Assert.Equal("Network error", exception.Message); Assert.Same(handler.Exception, exception.InnerException); Assert.Null(exception.HttpResponse); }
public async Task SuccessfulRequest() { var handler = new MockMessageHandler() { Response = @"{""foo"": ""bar""}", }; var factory = new MockHttpClientFactory(handler); var httpClient = new ErrorHandlingHttpClient <FirebaseException>( this.CreateArgs(factory)); var response = await httpClient.SendAndDeserializeAsync <Dictionary <string, string> >( this.CreateRequest()); Assert.NotNull(response.HttpResponse); Assert.Equal(handler.Response, response.Body); Assert.Single(response.Result); Assert.Equal("bar", response.Result["foo"]); Assert.Equal(1, handler.Calls); }
public async Task DeserializeError() { var handler = new MockMessageHandler() { Response = "not json", }; var factory = new MockHttpClientFactory(handler); var httpClient = new ErrorHandlingHttpClient <FirebaseException>( this.CreateArgs(factory)); var exception = await Assert.ThrowsAsync <FirebaseException>( async() => await httpClient.SendAndDeserializeAsync <Dictionary <string, string> >( this.CreateRequest())); Assert.Equal(ErrorCode.Unknown, exception.ErrorCode); Assert.Equal("Response parse error", exception.Message); Assert.NotNull(exception.InnerException); Assert.NotNull(exception.HttpResponse); }
internal FirebaseUserManager(FirebaseUserManagerArgs args) { if (string.IsNullOrEmpty(args.ProjectId)) { throw new ArgumentException( "Must initialize FirebaseApp with a project ID to manage users."); } this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>( new ErrorHandlingHttpClientArgs <FirebaseAuthException>() { HttpClientFactory = args.ClientFactory, Credential = args.Credential, ErrorResponseHandler = AuthErrorHandler.Instance, RequestExceptionHandler = AuthErrorHandler.Instance, DeserializeExceptionHandler = AuthErrorHandler.Instance, }); this.baseUrl = string.Format(IdTooklitUrl, args.ProjectId); }
public async Task ErrorResponse() { var handler = new MockMessageHandler() { StatusCode = HttpStatusCode.InternalServerError, Response = "{}", }; var factory = new MockHttpClientFactory(handler); var httpClient = new ErrorHandlingHttpClient <FirebaseException>( this.CreateArgs(factory)); var exception = await Assert.ThrowsAsync <FirebaseException>( async() => await httpClient.SendAndDeserializeAsync <Dictionary <string, string> >( this.CreateRequest())); Assert.Equal(ErrorCode.Internal, exception.ErrorCode); Assert.Equal("Example error message: {}", exception.Message); Assert.Null(exception.InnerException); Assert.NotNull(exception.HttpResponse); }
internal TenantManager(Args args) { if (string.IsNullOrEmpty(args.ProjectId)) { throw new ArgumentException( "Must initialize FirebaseApp with a project ID to manage tenants."); } this.EmulatorHost = args.EmulatorHost; this.app = args.App; this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>( args.ToHttpClientArgs()); var options = new Utils.UrlOptions { ApiVersion = "v2", EmulatorHost = this.EmulatorHost, }; this.baseUrl = Utils.BuildAuthUrl(args.ProjectId, options); }
public async Task SuccessfulAuthorizedRequest() { var handler = new MockMessageHandler() { Response = @"{""foo"": ""bar""}", }; var factory = new MockHttpClientFactory(handler); var credential = GoogleCredential.FromAccessToken("test-token"); var httpClient = new ErrorHandlingHttpClient <FirebaseException>( this.CreateArgs(factory, credential)); var response = await httpClient.SendAndDeserializeAsync <Dictionary <string, string> >( this.CreateRequest()); Assert.NotNull(response.HttpResponse); Assert.Equal(handler.Response, response.Body); Assert.Single(response.Result); Assert.Equal("bar", response.Result["foo"]); Assert.Equal(1, handler.Calls); Assert.Equal( "Bearer test-token", handler.LastRequestHeaders.GetValues("Authorization").First()); }
internal FirebaseUserManager(Args args) { if (string.IsNullOrEmpty(args.ProjectId)) { throw new ArgumentException( "Must initialize FirebaseApp with a project ID to manage users."); } this.TenantId = args.TenantId; if (this.TenantId == string.Empty) { throw new ArgumentException("Tenant ID must not be empty."); } this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>( new ErrorHandlingHttpClientArgs <FirebaseAuthException>() { HttpClientFactory = args.ClientFactory, Credential = args.Credential, ErrorResponseHandler = AuthErrorHandler.Instance, RequestExceptionHandler = AuthErrorHandler.Instance, DeserializeExceptionHandler = AuthErrorHandler.Instance, RetryOptions = args.RetryOptions, }); this.clock = args.Clock ?? SystemClock.Default; var baseUrl = string.Format(IdToolkitUrl, args.ProjectId); if (this.TenantId != null) { this.baseUrl = $"{baseUrl}/tenants/{this.TenantId}"; } else { this.baseUrl = baseUrl; } }
internal FirebaseUserManager(Args args) { this.ProjectId = args.ProjectId; if (string.IsNullOrEmpty(this.ProjectId)) { throw new ArgumentException( "Must initialize FirebaseApp with a project ID to manage users."); } this.TenantId = args.TenantId; if (this.TenantId == string.Empty) { throw new ArgumentException("Tenant ID must not be empty."); } this.EmulatorHost = args.EmulatorHost; this.httpClient = new ErrorHandlingHttpClient <FirebaseAuthException>( new ErrorHandlingHttpClientArgs <FirebaseAuthException>() { HttpClientFactory = args.ClientFactory, Credential = Utils.ResolveCredentials(this.EmulatorHost, args.Credential), ErrorResponseHandler = AuthErrorHandler.Instance, RequestExceptionHandler = AuthErrorHandler.Instance, DeserializeExceptionHandler = AuthErrorHandler.Instance, RetryOptions = args.RetryOptions, }); this.clock = args.Clock ?? SystemClock.Default; var options = new Utils.UrlOptions { TenantId = this.TenantId, EmulatorHost = this.EmulatorHost, }; this.baseUrl = Utils.BuildAuthUrl(this.ProjectId, options); }