Closed GoogleCodeExporter closed 9 years ago
I have fixed the issue by replacing the method with this:
@Override
@Beta
protected TokenResponse executeRefreshToken() throws IOException {
if (serviceAccountPrivateKey == null) {
return super.executeRefreshToken();
}
// service accounts: no refresh token; instead use private key to
// request new access token
JsonWebSignature.Header header = new JsonWebSignature.Header();
header.setAlgorithm("RS256");
header.setType("JWT");
JsonWebToken.Payload payload = new JsonWebToken.Payload();
long currentTime = getClock().currentTimeMillis();
payload.setIssuer(serviceAccountId);
payload.setAudience(getTokenServerEncodedUrl());
payload.setIssuedAtTimeSeconds(currentTime / 1000);
payload.setExpirationTimeSeconds(currentTime / 1000 + 3600);
payload.set("prn", serviceAccountUser);
payload.put("scope", Joiner.on(' ').join(serviceAccountScopes));
try {
String assertion = JsonWebSignature.signUsingRsaSha256(serviceAccountPrivateKey, getJsonFactory(), header, payload);
TokenRequest request = new TokenRequest(getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()), "assertion");
request.put("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");
request.put("assertion", assertion);
return request.execute();
} catch (GeneralSecurityException exception) {
IOException e = new IOException();
e.initCause(exception);
throw e;
}
}
Original comment by daniel.florey@gmail.com
on 25 Mar 2014 at 12:36
Daniel, please investigate.
Original comment by yan...@google.com
on 25 Mar 2014 at 1:55
For some reason it is working now - even without the patch.
Most likely just an issue with the OAuth endpoint today(?)
Sorry for the noise.
Original comment by daniel.florey@gmail.com
on 25 Mar 2014 at 3:04
Hi, is your application having too many instances simultaneously sending
"refresh_token" requests with the same access token?
Original comment by wonder...@google.com
on 25 Mar 2014 at 6:01
I tried to figure out if a user comes from a Google Apps domain and has
installed our app from the marketplace so that service accounts can be used. I
grabbed a service account access token on login to detect this. It turned out
that the oauth2 endpoint did not like multiple access token requests for the
same user.
When only requesting new access tokens when the old ones are about to expire it
seems to work more reliable.
Original comment by daniel.florey@gmail.com
on 25 Mar 2014 at 6:06
If you have too many instances that sends out "refresh_token" requests for the
same access token simultaneously, you will hit the "rate limit" at the endpoint
and therefore get a 403 error.
By the way, were you using GData APIs or any of the new APIs listed on
https://developers.google.com/api-client-library/java/apis/ ?
Original comment by wonder...@google.com
on 25 Mar 2014 at 6:33
Original comment by wonder...@google.com
on 13 May 2014 at 5:57
Original issue reported on code.google.com by
daniel.florey@gmail.com
on 25 Mar 2014 at 11:58