GM1313
GM1313

Reputation: 49

Google Cloud Platform API oauth_service_token with R (httr)

I am trying to get API access to GCP, and the httr oauth_service_token() call does not work for my endpoint... appreciate any help. The json key file works with an equivalent python program, so the key file itself is fine.

If I uncomment the line for oauth_endpoints("google"), I do get the token for Google accounts - so the oauth_ code itself seems OK, but just not for GCP. I tried other random access URLs, but the one below is what the REST API specifies.

keyFile <- "TwitterAPI-App-51ca9b46ce60.json"
endpoint <- oauth_endpoint(authorize= "https://www.googleapis.com/oauth2/v3/token", 
                          access = "https://www.googleapis.com/oauth2/v3/token", 
                           base_url = "https://www.googleapis.com")
# endpoint <- oauth_endpoints("google") # default is for accounts.google.com, I need GCP access

secrets <- jsonlite::fromJSON(keyFile)
scope <- "https://www.googleapis.com/auth/devstorage.read_write"

gtoken <- oauth_service_token(endpoint, secrets, scope) => GCP token fails, google account works

Upvotes: 1

Views: 336

Answers (1)

GM1313
GM1313

Reputation: 49

I saw the bug in httr code. The aud is hardcoded and does not take the value in the endpoint. I need to figure out how to do a pull request for the fix..

https://github.com/hadley/httr/blob/master/R/oauth-server-side.R

jwt_claimset <- function(iss, scope,
                         aud = "https://accounts.google.com/o/oauth2/token",
                         exp = NULL, iat = NULL) {

Upvotes: 1

Related Questions