1 // Copyright 2014 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.
5 #include "components/signin/core/browser/signin_oauth_helper.h"
7 #include "base/message_loop/message_loop.h"
8 #include "google_apis/gaia/gaia_auth_fetcher.h"
9 #include "google_apis/gaia/gaia_constants.h"
11 SigninOAuthHelper::SigninOAuthHelper(net::URLRequestContextGetter
* getter
,
12 const std::string
& session_index
,
13 const std::string
& signin_scoped_device_id
,
15 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource
, getter
),
19 DCHECK(!session_index
.empty());
20 gaia_auth_fetcher_
.StartCookieForOAuthLoginTokenExchangeWithDeviceId(
21 session_index
, signin_scoped_device_id
);
24 SigninOAuthHelper::~SigninOAuthHelper() {}
26 void SigninOAuthHelper::OnClientOAuthSuccess(const ClientOAuthResult
& result
) {
27 refresh_token_
= result
.refresh_token
;
28 gaia_auth_fetcher_
.StartOAuthLogin(result
.access_token
,
29 GaiaConstants::kGaiaService
);
32 void SigninOAuthHelper::OnClientOAuthFailure(
33 const GoogleServiceAuthError
& error
) {
34 VLOG(1) << "SigninOAuthHelper::OnClientOAuthFailure: " << error
.ToString();
35 consumer_
->OnSigninOAuthInformationFailure(error
);
38 void SigninOAuthHelper::OnClientLoginSuccess(const ClientLoginResult
& result
) {
39 gaia_auth_fetcher_
.StartGetUserInfo(result
.lsid
);
42 void SigninOAuthHelper::OnClientLoginFailure(
43 const GoogleServiceAuthError
& error
) {
44 VLOG(1) << "SigninOAuthHelper::OnClientLoginFailure: " << error
.ToString();
45 consumer_
->OnSigninOAuthInformationFailure(error
);
48 void SigninOAuthHelper::OnGetUserInfoSuccess(const UserInfoMap
& data
) {
49 UserInfoMap::const_iterator email_iter
= data
.find("email");
50 UserInfoMap::const_iterator display_email_iter
= data
.find("displayEmail");
51 if (email_iter
== data
.end() || display_email_iter
== data
.end()) {
52 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess: no email found:"
53 << " email=" << email_iter
->second
54 << " displayEmail=" << display_email_iter
->second
;
55 consumer_
->OnSigninOAuthInformationFailure(
56 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR
));
58 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess:"
59 << " email=" << email_iter
->second
60 << " displayEmail=" << display_email_iter
->second
;
61 consumer_
->OnSigninOAuthInformationAvailable(
62 email_iter
->second
, display_email_iter
->second
, refresh_token_
);
66 void SigninOAuthHelper::OnGetUserInfoFailure(
67 const GoogleServiceAuthError
& error
) {
68 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoFailure : " << error
.ToString();
69 consumer_
->OnSigninOAuthInformationFailure(error
);