| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h" | 5 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 13 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 14 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 14 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 15 #include "components/signin/core/browser/signin_manager.h" | 15 #include "components/signin/core/browser/signin_manager.h" |
| 16 #include "google_apis/gaia/gaia_urls.h" | 16 #include "google_apis/gaia/gaia_urls.h" |
| 17 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 GaiaWebAuthFlow::GaiaWebAuthFlow(Delegate* delegate, | 21 GaiaWebAuthFlow::GaiaWebAuthFlow(Delegate* delegate, |
| 22 Profile* profile, | 22 Profile* profile, |
| 23 const std::string& account_id, |
| 23 const std::string& extension_id, | 24 const std::string& extension_id, |
| 24 const OAuth2Info& oauth2_info, | 25 const OAuth2Info& oauth2_info, |
| 25 const std::string& locale) | 26 const std::string& locale) |
| 26 : delegate_(delegate), | 27 : delegate_(delegate), profile_(profile), account_id_(account_id) { |
| 27 profile_(profile) { | |
| 28 const char kOAuth2RedirectPathFormat[] = "/%s#"; | 28 const char kOAuth2RedirectPathFormat[] = "/%s#"; |
| 29 const char kOAuth2AuthorizeFormat[] = | 29 const char kOAuth2AuthorizeFormat[] = |
| 30 "?response_type=token&approval_prompt=force&authuser=0&" | 30 "?response_type=token&approval_prompt=force&authuser=0&" |
| 31 "client_id=%s&" | 31 "client_id=%s&" |
| 32 "scope=%s&" | 32 "scope=%s&" |
| 33 "origin=chrome-extension://%s/&" | 33 "origin=chrome-extension://%s/&" |
| 34 "redirect_uri=%s:/%s&" | 34 "redirect_uri=%s:/%s&" |
| 35 "hl=%s"; | 35 "hl=%s"; |
| 36 | 36 |
| 37 std::vector<std::string> client_id_parts; | 37 std::vector<std::string> client_id_parts; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 if (web_flow_) | 57 if (web_flow_) |
| 58 web_flow_.release()->DetachDelegateAndDelete(); | 58 web_flow_.release()->DetachDelegateAndDelete(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void GaiaWebAuthFlow::Start() { | 61 void GaiaWebAuthFlow::Start() { |
| 62 ProfileOAuth2TokenService* token_service = | 62 ProfileOAuth2TokenService* token_service = |
| 63 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 63 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 64 ubertoken_fetcher_.reset(new UbertokenFetcher(token_service, | 64 ubertoken_fetcher_.reset(new UbertokenFetcher(token_service, |
| 65 this, | 65 this, |
| 66 profile_->GetRequestContext())); | 66 profile_->GetRequestContext())); |
| 67 SigninManagerBase* signin_manager = | 67 ubertoken_fetcher_->StartFetchingToken(account_id_); |
| 68 SigninManagerFactory::GetForProfile(profile_); | |
| 69 ubertoken_fetcher_->StartFetchingToken( | |
| 70 signin_manager->GetAuthenticatedAccountId()); | |
| 71 } | 68 } |
| 72 | 69 |
| 73 void GaiaWebAuthFlow::OnUbertokenSuccess(const std::string& token) { | 70 void GaiaWebAuthFlow::OnUbertokenSuccess(const std::string& token) { |
| 74 const char kMergeSessionQueryFormat[] = "?uberauth=%s&" | 71 const char kMergeSessionQueryFormat[] = "?uberauth=%s&" |
| 75 "continue=%s&" | 72 "continue=%s&" |
| 76 "source=appsv2"; | 73 "source=appsv2"; |
| 77 | 74 |
| 78 std::string merge_query = base::StringPrintf( | 75 std::string merge_query = base::StringPrintf( |
| 79 kMergeSessionQueryFormat, | 76 kMergeSessionQueryFormat, |
| 80 net::EscapeUrlEncodedData(token, true).c_str(), | 77 net::EscapeUrlEncodedData(token, true).c_str(), |
| 81 net::EscapeUrlEncodedData(auth_url_.spec(), true).c_str()); | 78 net::EscapeUrlEncodedData(auth_url_.spec(), true).c_str()); |
| 82 GURL merge_url( | 79 GURL merge_url( |
| 83 GaiaUrls::GetInstance()->merge_session_url().Resolve(merge_query)); | 80 GaiaUrls::GetInstance()->merge_session_url().Resolve(merge_query)); |
| 84 | 81 |
| 85 web_flow_ = CreateWebAuthFlow(merge_url); | 82 web_flow_ = CreateWebAuthFlow(merge_url); |
| 86 web_flow_->Start(); | 83 web_flow_->Start(); |
| 87 } | 84 } |
| 88 | 85 |
| 89 void GaiaWebAuthFlow::OnUbertokenFailure(const GoogleServiceAuthError& error) { | 86 void GaiaWebAuthFlow::OnUbertokenFailure(const GoogleServiceAuthError& error) { |
| 87 DVLOG(1) << "OnUbertokenFailure: " << error.error_message(); |
| 90 delegate_->OnGaiaFlowFailure( | 88 delegate_->OnGaiaFlowFailure( |
| 91 GaiaWebAuthFlow::SERVICE_AUTH_ERROR, error, std::string()); | 89 GaiaWebAuthFlow::SERVICE_AUTH_ERROR, error, std::string()); |
| 92 } | 90 } |
| 93 | 91 |
| 94 void GaiaWebAuthFlow::OnAuthFlowFailure(WebAuthFlow::Failure failure) { | 92 void GaiaWebAuthFlow::OnAuthFlowFailure(WebAuthFlow::Failure failure) { |
| 95 GaiaWebAuthFlow::Failure gaia_failure; | 93 GaiaWebAuthFlow::Failure gaia_failure; |
| 96 | 94 |
| 97 switch (failure) { | 95 switch (failure) { |
| 98 case WebAuthFlow::WINDOW_CLOSED: | 96 case WebAuthFlow::WINDOW_CLOSED: |
| 99 gaia_failure = GaiaWebAuthFlow::WINDOW_CLOSED; | 97 gaia_failure = GaiaWebAuthFlow::WINDOW_CLOSED; |
| 100 break; | 98 break; |
| 101 case WebAuthFlow::LOAD_FAILED: | 99 case WebAuthFlow::LOAD_FAILED: |
| 100 DVLOG(1) << "OnAuthFlowFailure LOAD_FAILED"; |
| 102 gaia_failure = GaiaWebAuthFlow::LOAD_FAILED; | 101 gaia_failure = GaiaWebAuthFlow::LOAD_FAILED; |
| 103 break; | 102 break; |
| 104 default: | 103 default: |
| 105 NOTREACHED() << "Unexpected error from web auth flow: " << failure; | 104 NOTREACHED() << "Unexpected error from web auth flow: " << failure; |
| 106 gaia_failure = GaiaWebAuthFlow::LOAD_FAILED; | 105 gaia_failure = GaiaWebAuthFlow::LOAD_FAILED; |
| 107 break; | 106 break; |
| 108 } | 107 } |
| 109 | 108 |
| 110 delegate_->OnGaiaFlowFailure( | 109 delegate_->OnGaiaFlowFailure( |
| 111 gaia_failure, | 110 gaia_failure, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 177 } |
| 179 | 178 |
| 180 scoped_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) { | 179 scoped_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) { |
| 181 return scoped_ptr<WebAuthFlow>(new WebAuthFlow(this, | 180 return scoped_ptr<WebAuthFlow>(new WebAuthFlow(this, |
| 182 profile_, | 181 profile_, |
| 183 url, | 182 url, |
| 184 WebAuthFlow::INTERACTIVE)); | 183 WebAuthFlow::INTERACTIVE)); |
| 185 } | 184 } |
| 186 | 185 |
| 187 } // namespace extensions | 186 } // namespace extensions |
| OLD | NEW |