@@ -67,32 +67,21 @@ ParseImpersonatedServiceAccountCredentials(std::string const& content,
6767 }
6868 // We strip the service account from the path URL.
6969 auto url = it->get <std::string>();
70- auto colon = url.rfind (' :' );
71- if (colon == std::string::npos) {
72- return internal::InvalidArgumentError (
73- " Malformed `service_account_impersonation_url` field contents on data "
74- " from " +
75- source,
76- GCP_ERROR_INFO ());
77- }
78- if (url.substr (colon) != " :generateAccessToken" ) {
79- // While `generateIdToken` is a valid RPC, we do not currently support ID
80- // token flow. So we might as well error when parsing the credentials.
81- return internal::InvalidArgumentError (
82- " Only access token authentication is supported for impersonated "
83- " service accounts from " +
84- source,
85- GCP_ERROR_INFO ());
86- }
87- auto slash = url.rfind (' /' , colon);
70+ auto slash = url.rfind (' /' );
8871 if (slash == std::string::npos) {
8972 return internal::InvalidArgumentError (
9073 " Malformed `service_account_impersonation_url` field contents on data "
9174 " from " +
9275 source,
9376 GCP_ERROR_INFO ());
9477 }
95- info.service_account = std::string{url.substr (slash + 1 , colon - slash - 1 )};
78+
79+ // In the url, after the last slash, it is in the format of
80+ // `service_account[:action]`
81+ auto service_account_action = url.substr (slash + 1 );
82+ auto colon = service_account_action.rfind (' :' );
83+ auto end = colon == std::string::npos ? service_account_action.size () : colon;
84+ info.service_account = service_account_action.substr (0 , end);
9685
9786 it = credentials.find (" delegates" );
9887 if (it != credentials.end ()) {
0 commit comments