Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when sending message using a quota project #444

Open
SMLVE opened this issue Jan 10, 2025 · 0 comments
Open

Error when sending message using a quota project #444

SMLVE opened this issue Jan 10, 2025 · 0 comments

Comments

@SMLVE
Copy link

SMLVE commented Jan 10, 2025

[REQUIRED] Step 2: Describe your environment

We are running our API on Google's cloud run.

  • Firebase SDK version: FirebaseAdmin version 3.1.0
  • Firebase Product: Messaging
  • .NET version: 8.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

We are creating a FirebaseApp and retrieving the FirebaseMessaging instance via this code:

public FirebaseMessaging GetFirebaseMessaging()
{
   var apiKey = _contextService.ApiKey;

   var app = _apps.GetOrAdd(apiKey, key =>
   {
       var projectId = $"{_firebaseSettings.Value.ProjectIdPrefix}{key[..8]}-{key[^12..]}";
       var credential = GoogleCredential.GetApplicationDefault().CreateWithQuotaProject(projectId);

       var options = new AppOptions
       {
           Credential = credential,
           ProjectId = projectId,
           HttpClientFactory = _httpClientFactory
       };

       return FirebaseApp.Create(options, key);
   });

   return FirebaseMessaging.GetMessaging(app);
}

With the value returned by the previous method, we send a message using the following code:

var messageId = await messaging.SendAsync(message, cancellationToken);

but we sometimes get the following error:

System.InvalidOperationException: x-goog-user-project header can only be added through the credential or through the <Product>ClientBuilder.
   at Google.Apis.Http.ConfigurableMessageHandler.CheckValidAfterInterceptors(HttpRequestMessage request)
   at Google.Apis.Http.ConfigurableMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndReadAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndDeserializeAsync[TResult](HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessagingClient.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, CancellationToken cancellationToken)
   at Campaigns.Data.Clients.PushNotificationClient.SendPushNotificationAsync(SendPushNotification pushNotification, CancellationToken cancellationToken) in /src/campaign/src/Campaigns.Data/Clients/PushNotificationClient.cs:line 33

I may be missing something, but the x-goog-user-project header is added automatically via the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants