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); }
/// <summary> /// Creates an authenticated <see cref="ConfigurableHttpClient"/> from the /// factory. /// </summary> /// <returns>An HTTP client that can be used to OAuth2 authorized requests.</returns> /// <param name="clientFactory">The <see cref="HttpClientFactory"/> used to create /// the HTTP client.</param> /// <param name="credential">The Google credential that will be used to authenticate /// outgoing HTTP requests.</param> public static ConfigurableHttpClient CreateAuthorizedHttpClient( this HttpClientFactory clientFactory, GoogleCredential credential) { var args = new CreateHttpClientArgs(); args.Initializers.Add(credential.ThrowIfNull(nameof(credential))); return(clientFactory.CreateHttpClient(args)); }
/// <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, }); }