Created
January 25, 2019 17:08
Method to exchange JWT for Google-signed OIDC token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private DecodedJWT getGoogleIdToken() throws IOException { | |
String jwt = getSignedJwt(); | |
final GenericData tokenRequest = new GenericData() | |
.set("grant_type", JWT_BEARER_TOKEN_GRANT_TYPE) | |
.set("assertion", jwt); | |
final UrlEncodedContent content = new UrlEncodedContent(tokenRequest); | |
final HttpRequestFactory requestFactory = httpTransport.createRequestFactory(); | |
final HttpRequest request = requestFactory | |
.buildPostRequest(new GenericUrl(OAUTH_TOKEN_URI), content) | |
.setParser(new JsonObjectParser(JacksonFactory.getDefaultInstance())); | |
HttpResponse response = request.execute(); | |
GenericData responseData = response.parseAs(GenericData.class); | |
String idToken = (String) responseData.get("id_token"); | |
return JWT.decode(idToken); | |
} |
That's helpful. Thanks a ton.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is JWT_BEARER_TOKEN_GRANT_TYPE enum ?
Do you know what the value in here can be ? JWT_BEARER_TOKEN_GRANT_TYPE