firebase / firebase/firebase-admin-dotnet

Authentication Error

Open
#503 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
408
Forks
146
Avg merge
22h 7m
Merged PRs (30d)
1

Description

FirebaseAdmin: 3.4.0
.NET Version: 10

My firebase messaging stopped working all suddenly, no code changes, Firebase Messaging API enabled, Service Account credential is active.

**Setup code in my service**
```
var credential = CredentialFactory.FromFile(options.Value.FIREBASE_ADMIN_FILE);
_app = FirebaseApp.Create(new AppOptions()
{
Credential = credential.ToGoogleCredential(),
});
_messaging = FirebaseMessaging.GetMessaging(_app);
```

**When attempting to send a message, I now get the errors below:**

FirebaseAdmin.Messaging.FirebaseMessagingException: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

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 NoWow.EmailService.FirebaseClient.NotifyAsync(Guid userId, String token, String title, String body, Dictionary`2 data, CancellationToken cancellationToken) in /src/src/NoWow.EmailService/FirebaseClient.cs:line 67

**To confirm my credentials is valid I did:**

```
var credential = CredentialFactory.FromFile(options.Value.FIREBASE_ADMIN_FILE).ToGoogleCredential().CreateScoped(
"https://www.googleapis.com/auth/firebase.messaging",
"https://www.googleapis.com/auth/cloud-platform");
var accessTokenForRequestAsync = await credential.UnderlyingCredential.GetAccessTokenForRequestAsync();
Console.WriteLine("Access token: {0}", accessTokenForRequestAsync);
```
The above test returned an access token confirming my credentials are valid

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.