How to add multiple target_audience in google authentication jwt?

1.4k views Asked by At

I need to get id token for multiple specific services from the google oauth2 service.

{"typ":"JWT","alg":"RS256"}.{"aud":"https://www.googleapis.com/oauth2/v4/token","exp":"1566830430","iat":"1566827130","iss":"my_project.iam.gserviceaccount.com","target_audience", "www.myservice.com/location"}

It returns me and id token to post any data to the location service but I would like post data to my time service (www.myservice.com/time) too.

How can I set these 2 URLs as the target audience?

1

There are 1 answers

3
user2705223 On

The field does not currently support setting multiple values.

Consider sending a self-signed JWT [1] to https://iamcredentials.googleapis.com/v1/{name=projects//serviceAccounts/}:generateIdToken [2] instead. Even though it doesn't support multiple audiences in one call either, it is still the correct API to use to obtain ID tokens for your service account.

[1] https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt-auth

[2] https://cloud.google.com/iam/credentials/reference/rest/v1/projects.serviceAccounts/generateIdToken