| 265 | } |
| 266 | |
| 267 | Status 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 |