| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/arc/auth/arc_auth_fetcher.h" | |
| 6 | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "google_apis/gaia/gaia_constants.h" | |
| 9 #include "google_apis/gaia/gaia_urls.h" | |
| 10 | |
| 11 namespace arc { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const char kGMSCoreClientId[] = | |
| 16 "1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.googleusercontent.com"; | |
| 17 | |
| 18 } // namespace | |
| 19 | |
| 20 ArcAuthFetcher::ArcAuthFetcher(net::URLRequestContextGetter* getter, | |
| 21 Delegate* delegate) | |
| 22 : delegate_(delegate), auth_fetcher_(this, std::string(), getter) { | |
| 23 FetchAuthCode(); | |
| 24 } | |
| 25 | |
| 26 // static | |
| 27 GURL ArcAuthFetcher::CreateURL() { | |
| 28 std::string query_string = | |
| 29 base::StringPrintf("?scope=%s&client_id=%s", | |
| 30 GaiaConstants::kOAuth1LoginScope, kGMSCoreClientId); | |
| 31 return GaiaUrls::GetInstance()->client_login_to_oauth2_url().Resolve( | |
| 32 query_string); | |
| 33 } | |
| 34 | |
| 35 void ArcAuthFetcher::FetchAuthCode() { | |
| 36 DCHECK(!auth_fetcher_.HasPendingFetch()); | |
| 37 auth_fetcher_.StartCookieForOAuthLoginTokenExchange( | |
| 38 false, /* fetch_token_from_auth_code */ | |
| 39 std::string(), /* session_index */ | |
| 40 kGMSCoreClientId, std::string() /* device_id */); | |
| 41 } | |
| 42 | |
| 43 void ArcAuthFetcher::OnClientOAuthCode(const std::string& auth_code) { | |
| 44 DCHECK(!auth_fetcher_.HasPendingFetch()); | |
| 45 delegate_->OnAuthCodeFetched(auth_code); | |
| 46 } | |
| 47 | |
| 48 void ArcAuthFetcher::OnClientOAuthFailure(const GoogleServiceAuthError& error) { | |
| 49 // UNEXPECTED_SERVICE_RESPONSE indicates no cookies in response, but request | |
| 50 // is completed successfully. | |
| 51 if (error.state() == GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE) { | |
| 52 delegate_->OnAuthCodeNeedUI(); | |
| 53 } else { | |
| 54 VLOG(2) << "ARC Auth request failed: " << error.ToString() << "."; | |
| 55 delegate_->OnAuthCodeFailed(); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 } // namespace arc | |
| OLD | NEW |