googleapis / googleapis/google-cloud-java

[google-auth-library-java] UserAuthorizer is discarding the id_token after successful authorization code exchange

Đang mở
#12,606 1 bình luận 0 reaction 1 người được giao Được @TimurSadykov nhận Xem trên GitHub
type: feature request
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

I'm trying to get data from the `id_token` which is returned when exchanging an authorization code with the token endpoint.

I have everything I need to make the request to the endpoint manually. However, this is very verbose and feels like re-inventing the wheel. It got me thinking that there must be a way to get this data using the classes provided by the library.

Currently I am using the `com.google.auth.oauth2.UserAuthorizer` class to build up a request for the exchange of information.

```
val userCredentials: UserCredentials = UserAuthorizer.newBuilder()
.setClientId(googleOauthConfig.clientId)
.setTokenStore(tokenStore)
.setScopes(googleOauthConfig.scopes)
.setTokenServerUri(URI.create("https://oauth2.googleapis.com/token"))
.setCallbackUri(redirectUri)
.build()
.getCredentialsFromCode(authorizationCode, redirectUri)
```

The internals of `getCredentialsFromCode()` parses the response and it contains all the tokens. Including the `id_token` but, it gets discarded when constructing the `UserCredentials` object further down.

[![Debug mode showing that the value for id_token is stored][1]][1]

```
return UserCredentials.newBuilder()
.setClientId(clientId.getClientId())
.setClientSecret(clientId.getClientSecret())
.setRefreshToken(refreshToken)
.setAccessToken(accessToken)
.setHttpTransportFactory(transportFactory)
.setTokenServerUri(tokenServerUri)
.build(); // no mention of id_token
```

Regardless, I want to get this value so I can know basic information about the user such as their name, birthday and email address from a single request.

There does exist a method called `idTokenWithAudience()` which returns a Google ID Token from the refresh token response. If I call this, I get a token back that doesn't contain all the data that was available in the identically named `id_token` mentioned earlier making it a no-go either.

[1]: https://i.stack.imgur.com/zSMvN.png

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.