0

I need to send a notification using FCM REST API. However, I am unable to authenticaate using an API key at the moment. The below is the API to hit.

https://fcm.googleapis.com/v1/projects/proj-name/messages:send?key=XXX

The error I receive is as follows:

{
    "error": {
        "code": 401,
        "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
        "status": "UNAUTHENTICATED"
    }
}

The backend is in PHP so there isn't any supported package for it. Hence, I am trying to use it for sending the notification. The above API seem to take oauth 2 access token or login cookie or some auther vaidation method. However, I need to send it from my own REST API. How can I authenticate from PHP to the above API and send the notificaiton properly?

UPDATE::

LINK: Authenticate using Service Account

This API documents on how to authenticate using service accounts. Especially the below lines says the following:

Use credentials to mint access tokens
Unless you are using the Admin SDK, which handle authorization automatically, you'll need to mint the access token and add it to send requests.

Use your Firebase credentials together with the Google Auth Library for your preferred language to retrieve a short-lived OAuth 2.0 access token:

But it does not provide/document any method for minting the short lived access token.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ariel
  • 2,471
  • 1
  • 26
  • 43
  • What indicate the API documentation ? With Oauth2, the token is generaly sent in the header Authorization: Bearer access_token – svgta Jan 05 '23 at 11:04
  • I am looking for the API from which I can get the Oauth2 ID token. I need the ID token but the ID token where do I receive it? – Ariel Jan 05 '23 at 11:14
  • I'm confusing oauth2 and openId Connect. I don't remember if oauth2 give an id_token. But OIDC give id_token and access_token at the same time with the endpoint token. But id_token contains some user informations in it (it's a JWT). Access_token can give you theses informations with the endpoint userinfo – svgta Jan 05 '23 at 11:41
  • I would recommend you have a look at these: https://stackoverflow.com/questions/68174288/getting-firebase-bearer-token-by-simple-httpcall-postman https://stackoverflow.com/questions/50399170/what-bearer-token-should-i-be-using-for-firebase-cloud-messaging-testing https://stackoverflow.com/questions/74341945/oauth2-access-token-via-rest-http – Vaidehi Jamankar Jan 11 '23 at 10:05

0 Answers0