MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ParseOAuthResponse

Method ParseOAuthResponse

tensorflow/core/platform/cloud/oauth_client.cc:267–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267Status OAuthClient::ParseOAuthResponse(StringPiece response,
268 uint64 request_timestamp_sec,
269 string* token,
270 uint64* expiration_timestamp_sec) {
271 if (!token || !expiration_timestamp_sec) {
272 return errors::FailedPrecondition(
273 "'token' and 'expiration_timestamp_sec' cannot be nullptr.");
274 }
275 Json::Value root;
276 Json::Reader reader;
277 if (!reader.parse(response.begin(), response.end(), root)) {
278 return errors::Internal("Couldn't parse JSON response from OAuth server.");
279 }
280
281 string token_type;
282 TF_RETURN_IF_ERROR(ReadJsonString(root, "token_type", &token_type));
283 if (token_type != "Bearer") {
284 return errors::FailedPrecondition("Unexpected Oauth token type: " +
285 token_type);
286 }
287 int64 expires_in = 0;
288 TF_RETURN_IF_ERROR(ReadJsonInt(root, "expires_in", &expires_in));
289 *expiration_timestamp_sec = request_timestamp_sec + expires_in;
290 TF_RETURN_IF_ERROR(ReadJsonString(root, "access_token", token));
291
292 return Status::OK();
293}
294
295} // namespace tensorflow

Callers 2

TESTFunction · 0.80
GetTokenFromGceMethod · 0.80

Calls 7

FailedPreconditionFunction · 0.85
InternalFunction · 0.85
ReadJsonStringFunction · 0.85
ReadJsonIntFunction · 0.85
parseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

TESTFunction · 0.64