admin管理员组

文章数量:1391987

Following is my request

Request: POST :batchAdd Headers[access_token_auth=true authorization=eyJ0e_access_token Content-Type=application/json Body: {"registration_tokens":["xxccvc_dummy"],"to":"/topics/my_topic"}

and I am getting reponse

POST :batchAdd, Status[302 Moved Temporarily], Headers[Location=;passive=1209600 Content-Type=text/html;

This is how I am getting access token

Jwt.issuer(serviceEmail)
      .scope(";)
      .subject(serviceEmail)
      .claim("kid", myConfig.fcmJwtKid())
      .audience("/")
      .issuedAt(Instant.now())
      .expiresAt(Instant.now().plus(1, ChronoUnit.HOURS))
      .sign("jwt-private-key.pem");

I have gone through almost all the documentation but could not find any reason that why I could receive this?

Following is my request

Request: POST https://iid.googleapis/iid/v1:batchAdd Headers[access_token_auth=true authorization=eyJ0e_access_token Content-Type=application/json Body: {"registration_tokens":["xxccvc_dummy"],"to":"/topics/my_topic"}

and I am getting reponse

POST https://iid.googleapis/iid/v1:batchAdd, Status[302 Moved Temporarily], Headers[Location=https://accounts.google/ServiceLogin?service=ac2dm&passive=1209600 Content-Type=text/html;

This is how I am getting access token

Jwt.issuer(serviceEmail)
      .scope("https://www.googleapis/auth/cloud-platform")
      .subject(serviceEmail)
      .claim("kid", myConfig.fcmJwtKid())
      .audience("https://fcm.googleapis/")
      .issuedAt(Instant.now())
      .expiresAt(Instant.now().plus(1, ChronoUnit.HOURS))
      .sign("jwt-private-key.pem");

I have gone through almost all the documentation but could not find any reason that why I could receive this?

Share Improve this question asked Mar 14 at 15:19 FreakFreak 6,8935 gold badges40 silver badges56 bronze badges 1
  • 1 Have you tried following the (temporary) redirect? I'm unfamiliar with this service but it also appears to be deprecated (developers.google/instance-id/reference/server) – DazWilkin Commented Mar 14 at 18:02
Add a comment  | 

1 Answer 1

Reset to default 0

The scope https://www.googleapis/auth/cloud-platform is a very broad scope that grants access to many Google Cloud services, but it might not be specific enough for Firebase Cloud Messaging (FCM).

  • For FCM operations, a different scope is usually needed, specifically https://www.googleapis/auth/firebase.messaging.

  • Permissions to assign in IAM & Admin like Firebase Admin (roles/firebase.admin) and Cloud Messaging Admin (roles/firebase.messaging.admin).

Jwt.issuer(serviceEmail)
.scope("https://www.googleapis/auth/firebase.messaging") // Correct scope for FCM 
.subject(serviceEmail) .claim("kid", myConfig.fcmJwtKid())
.audience("https://fcm.googleapis/") // Ensure the audience is correct 
.issuedAt(Instant.now())
.expiresAt(Instant.now().plus(1, ChronoUnit.HOURS))
.sign("jwt-private-key.pem");

Correct Authorization Header in your request by trying to pass the authorization header in the correct format of Authorization: Bearer <access_token>:

POST https://iid.googleapis/iid/v1:batchAdd
Authorization: Bearer <your_access_token>
Content-Type: application/json

{
  "registration_tokens": ["xxccvc_dummy"],
  "to": "/topics/my_topic"
}

本文标签: javaGoogle cloud Identity api returns 302 when call batchAddStack Overflow