Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/signin/ubertoken_fetcher.cc

Issue 9301003: Change X-Auto-Login implementation to use OAuth token. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: With comments. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/logging.h"
6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/signin/token_service.h"
8 #include "chrome/browser/signin/ubertoken_fetcher.h"
9 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/net/gaia/gaia_constants.h"
11 #include "chrome/common/net/gaia/gaia_urls.h"
12 #include "chrome/common/net/gaia/google_service_auth_error.h"
13 #include "net/base/load_flags.h"
14
15 namespace {
16 // Url of the service to call to generate an über-auth token.
17 const char* kUberAuthTokenUrl =
18 "https://accounts.google.com/OAuthLogin?source=chrome&issueuberauth=1";
Roger Tawa OOO till Jul 10th 2012/01/31 21:38:23 i think this url should live in gaia_urls.h
qsr 2012/02/01 14:59:18 Change this to construct the url from urls in Gaia
19 } // namespace
20
21 UbertokenFetcher::UbertokenFetcher(Profile* profile,
22 UbertokenConsumer* consumer)
23 : profile_(profile), consumer_(consumer) {
24 DCHECK(profile);
25 DCHECK(consumer);
26 }
27
28 UbertokenFetcher::~UbertokenFetcher() {}
Roger Tawa OOO till Jul 10th 2012/01/31 21:38:23 closing brace on next line
qsr 2012/02/01 14:59:18 Done.
29
30 void UbertokenFetcher::StartFetchingToken() {
31 TokenService* token_service = profile_->GetTokenService();
32 if (token_service->HasOAuthLoginToken()) {
33 StartFetchingUbertoken();
34 } else {
35 registrar_.Add(this,
36 chrome::NOTIFICATION_TOKEN_AVAILABLE,
37 content::Source<TokenService>(token_service));
38 registrar_.Add(this,
39 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
40 content::Source<TokenService>(token_service));
41 token_service->StartFetchingTokens();
42 }
43 }
44
45 void UbertokenFetcher::StartFetchingUbertoken() {
46 TokenService* token_service = profile_->GetTokenService();
47 DCHECK(token_service->HasOAuthLoginToken());
48 gaia::OAuthClientInfo client_info;
49 GaiaUrls* urls = GaiaUrls::GetInstance();
50 client_info.client_id = urls->oauth2_chrome_client_id();
51 client_info.client_secret = urls->oauth2_chrome_client_secret();
52 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(
53 urls->oauth2_token_url(), profile_->GetRequestContext()));
54 gaia_oauth_client_->RefreshToken(
55 client_info, token_service->GetOAuth2LoginRefreshToken(), 1, this);
56 }
57
58 void UbertokenFetcher::Observe(int type,
59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) {
61 DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE ||
62 type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED);
63
64 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) {
65 TokenService::TokenAvailableDetails* token_details =
66 content::Details<TokenService::TokenAvailableDetails>(details).ptr();
67 if (token_details->service() !=
68 GaiaConstants::kGaiaOAuth2LoginRefreshToken) {
69 return;
70 }
71 registrar_.RemoveAll();
72 StartFetchingUbertoken();
73 } else {
74 TokenService::TokenRequestFailedDetails* token_details =
75 content::Details<TokenService::TokenRequestFailedDetails>(details).
76 ptr();
77 if (token_details->service() == GaiaConstants::kLSOService ||
78 token_details->service() ==
79 GaiaConstants::kGaiaOAuth2LoginRefreshToken) {
80 consumer_->OnUbertokenFailure(token_details->error());
81 }
82 }
83 }
84
85 void UbertokenFetcher::OnGetTokensResponse(const std::string& refresh_token,
86 const std::string& access_token,
87 int expires_in_seconds) {
88 NOTREACHED();
89 }
90
91 void UbertokenFetcher::OnRefreshTokenResponse(const std::string& access_token,
92 int expires_in_seconds) {
93 GURL url(kUberAuthTokenUrl);
94 url_fetcher_.reset(
95 content::URLFetcher::Create(0, url, content::URLFetcher::GET, this));
96 url_fetcher_->SetRequestContext(profile_->GetRequestContext());
97 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
98 net::LOAD_DO_NOT_SAVE_COOKIES);
99 url_fetcher_->SetExtraRequestHeaders("Authorization: OAuth " + access_token);
100 url_fetcher_->Start();
Roger Tawa OOO till Jul 10th 2012/01/31 21:38:23 I think it would be better to add this functionali
qsr 2012/02/01 14:59:18 If you strongly insist, I'll do it but: 1) GaiaAut
Roger Tawa OOO till Jul 10th 2012/02/01 15:29:55 Agree that keeping the uber token fetcher class he
qsr 2012/02/01 18:28:10 Done.
101 }
102
103 void UbertokenFetcher::OnOAuthError() {
104 GoogleServiceAuthError error(
105 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
106 consumer_->OnUbertokenFailure(error);
107 }
108
109 void UbertokenFetcher::OnNetworkError(int response_code) {
110 GoogleServiceAuthError error =
111 GoogleServiceAuthError::FromConnectionError(response_code);
112 consumer_->OnUbertokenFailure(error);
113 }
114
115 void UbertokenFetcher::OnURLFetchComplete(const content::URLFetcher* source) {
116 std::string response;
117 bool result = source->GetResponseAsString(&response);
118 DCHECK(result);
119 if (source->GetResponseCode() == 200) {
120 consumer_->OnUbertokenSuccess(response);
121 } else {
122 GoogleServiceAuthError error(
123 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
124 consumer_->OnUbertokenFailure(error);
125 }
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698