Skip to content

Commit

Permalink
fix(oauth2): do not require id_token in creds (#12867)
Browse files Browse the repository at this point in the history
Only a limited number of scopes returns this field. For the rest of scopes this field is not populated, which is ok.
  • Loading branch information
MeilakhSiarhei authored Oct 11, 2023
1 parent 953aefe commit f81fd55
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
3 changes: 1 addition & 2 deletions google/cloud/internal/oauth2_authorized_user_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ StatusOr<AccessToken> ParseAuthorizedUserRefreshResponse(
auto access_token = nlohmann::json::parse(*payload, nullptr, false);
if (access_token.is_discarded() || access_token.count("access_token") == 0 ||
access_token.count("expires_in") == 0 ||
access_token.count("id_token") == 0 ||
access_token.count("token_type") == 0) {
auto error_payload =
*payload +
"Could not find all required fields in response (access_token,"
" id_token, expires_in, token_type) while trying to obtain an access"
" expires_in, token_type) while trying to obtain an access"
" token for service account credentials.";
return AsStatus(status_code, error_payload);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ TEST_F(AuthorizedUserCredentialsTest, Simple) {
std::string response_payload = R"""({
"token_type": "Type",
"access_token": "access-token-value",
"id_token": "id-token-value",
"expires_in": 1234
})""";

Expand Down Expand Up @@ -223,7 +222,6 @@ TEST_F(AuthorizedUserCredentialsTest,
// Does not have access_token.
std::string r2 = R"""({
"token_type": "Type",
"id_token": "id-token-value",
"expires_in": 1000
})""";

Expand Down Expand Up @@ -260,7 +258,6 @@ TEST_F(AuthorizedUserCredentialsTest, ParseAuthorizedUserRefreshResponse) {
std::string r1 = R"""({
"token_type": "Type",
"access_token": "access-token-r1",
"id_token": "id-token-value",
"expires_in": 1000
})""";

Expand Down

0 comments on commit f81fd55

Please sign in to comment.