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

Side by Side Diff: chrome/browser/chromeos/login/oauth_login_manager.h

Issue 11649055: OAuth2 sign-in flow for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wired policy with OAuth2 path Created 7 years, 11 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) 2013 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_LOGIN_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_LOGIN_MANAGER_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/chromeos/cros/cert_library.h"
12 #include "chrome/browser/chromeos/cros/cros_library.h"
13 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h"
Joao da Silva 2013/01/11 16:45:07 Order
zel 2013/01/11 19:51:16 Done.
14 #include "chrome/browser/chromeos/login/oauth1_login_verifier.h"
15 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h"
16 #include "chrome/browser/chromeos/login/oauth2_login_verifier.h"
17 #include "chrome/browser/chromeos/login/oauth2_policy_fetcher.h"
18 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21
22 class GaiaAuthFetcher;
Joao da Silva 2013/01/11 16:45:07 Not needed
zel 2013/01/11 19:51:16 Done.
23 class GoogleServiceAuthError;
24 class Profile;
25 class TokenService;
26
27 namespace chromeos {
28
29 class OAuthLoginManager;
Joao da Silva 2013/01/11 16:45:07 Not needed
zel 2013/01/11 19:51:16 Done.
30
31 // This class is responsible for restoring authenticated web sessions out of
32 // OAuth tokens or vice versa.
33 class OAuthLoginManager {
34 public:
35 enum SessionRestoreState {
36 SESSION_RESTORE_NOT_STARTED,
37 SESSION_RESTORE_IN_PROGRESS,
38 SESSION_RESTORE_DONE,
39 };
40
41 class Delegate {
42 public:
43 virtual ~Delegate() {}
44 // Raised when cookie jar authentication is successfully completed.
45 virtual void OnCompletedAuthentication(Profile* user_profile) = 0;
46 // Raised when stored OAuth(1|2) tokens are found and authentication
47 // profile is no longer needed.
48 virtual void OnFoundStoredTokens() = 0;
49 // Raised when policy tokens are retrieved.
50 virtual void OnRestoredPolicyTokens() {}
51 };
52
53 explicit OAuthLoginManager(OAuthLoginManager::Delegate* delegate);
54 virtual ~OAuthLoginManager() {}
55 // Starts the process of retreiving policy tokens.
Joao da Silva 2013/01/11 16:45:07 *retrieving
zel 2013/01/11 19:51:16 Done.
56 virtual void RestorePolicyTokens(
57 net::URLRequestContextGetter* auth_request_context) = 0;
Joao da Silva 2013/01/11 16:45:07 #include "net/url_request/url_request_context_gett
zel 2013/01/11 19:51:16 Done.
58 // Restores and verifies OAuth tokens either from TokenService or previously
59 // authenticated cookie jar.
60 virtual void RestoreSession(
61 Profile* user_profile,
62 net::URLRequestContextGetter* auth_request_context,
63 bool restore_from_auth_cookies) = 0;
64 // Continues session restore after transient network errors.
65 virtual void ContinueSessionRestore() = 0;
66 // Stops all background authentication requests.
67 virtual void Stop() = 0;
68
69 // Stops all background authentication requests.
Joao da Silva 2013/01/11 16:45:07 Update comment?
zel 2013/01/11 19:51:16 Done.
70 SessionRestoreState state() { return state_; }
71
72 protected:
73 // Signals delegate that authentication is completed, kicks off token fetching
74 // process in TokenService.
75 void CompleteAuthentication();
76
77 OAuthLoginManager::Delegate* delegate_;
78 Profile* user_profile_;
79 scoped_refptr<net::URLRequestContextGetter> auth_request_context_;
Joao da Silva 2013/01/11 16:45:07 #include "base/memory/ref_counted.h"
zel 2013/01/11 19:51:16 Done.
80 bool restore_from_auth_cookies_;
81 SessionRestoreState state_;
82
83 DISALLOW_COPY_AND_ASSIGN(OAuthLoginManager);
84 };
85
86 class OAuthLoginManagerFactory {
Joao da Silva 2013/01/11 16:45:07 Document this class
zel 2013/01/11 19:51:16 Moved factory method into OAuthLoginManager instea
87 public:
88 static OAuthLoginManager* Create(OAuthLoginManager::Delegate* delegate);
89 };
90
91 // OAuth2 specialization of OAuthLoginManager.
92 class OAuth2LoginManager : public OAuthLoginManager,
93 public content::NotificationObserver,
94 public OAuth2LoginVerifier::Delegate,
95 public OAuth2TokenFetcher::Delegate {
96 public:
97 explicit OAuth2LoginManager(OAuthLoginManager::Delegate* delegate);
98
99 // OAuthLoginManager overrides.
100 virtual void RestorePolicyTokens(
101 net::URLRequestContextGetter* auth_request_context);
Joao da Silva 2013/01/11 16:45:07 OVERRIDE
zel 2013/01/11 19:51:16 Done.
102 virtual void RestoreSession(
103 Profile* user_profile,
104 net::URLRequestContextGetter* auth_request_context,
105 bool restore_from_auth_cookies) OVERRIDE;
106 virtual void ContinueSessionRestore() OVERRIDE;
107 virtual void Stop() OVERRIDE;
108
109 private:
110 // content::NotificationObserver overrides.
111 void Observe(int type,
112 const content::NotificationSource& source,
113 const content::NotificationDetails& details) OVERRIDE;
114
115 // OAuth2LoginVerifier::Delegate overrides.
116 virtual void OnOAuth2LoginVerifierSuccess(const std::string& sid,
117 const std::string& lsid,
118 const std::string& auth) OVERRIDE;
119 virtual void OnOAuth2LoginVerifierFaulure() OVERRIDE;
Joao da Silva 2013/01/11 16:45:07 *Failure
Joao da Silva 2013/01/11 16:45:07 *Failure
zel 2013/01/11 19:51:16 Done.
120
121 // OAuth2TokenFetcher::Delegate overrides.
122 virtual void OnOAuth2TokenAvailable(
123 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials,
124 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE;
125 virtual void OnOAuth2TokenFetchFailed() OVERRIDE;
126
127 // Retrieves TokenService for |user_profile_| and sets up notification
128 // observer events.
129 TokenService* SetupTokenService();
130 // Removes legacy tokens form OAuth1 flow.
131 void RemoveLegacyTokens();
132 // Loads previously stored OAuth2 tokens and kicks off its validation.
133 void LoadAndVerifyOAuth2Tokens();
134 // Attempts to fetch OAuth2 tokens by using pre-authenticated cookie jar from
135 // provided |auth_profile|.
136 void FetchOAuth2Tokens();
137 // Reports when all tokens are loaded.
138 void ReportOAuth2TokensLoaded();
139 // Issue GAIA cookie recovery (MergeSession) from |uber_token_|.
Joao da Silva 2013/01/11 16:45:07 What is uber_token_?
zel 2013/01/11 19:51:16 Done.
140 void RestoreSessionCookies();
141 // Fetches device policy OAuth2 access tokens if have not attempted or
142 // failed that step previously.
143 void FetchPolicyTokens();
144 // Checks GAIA error and figures out whether the request should be
145 // re-attempted.
146 bool RetryOnError(const GoogleServiceAuthError& error);
147
148 // Keeps the track if we have already reported OAuth2 token being loaded
149 // by TokenService.
150 bool loading_reported_;
151 int restore_attempt_count_;
Joao da Silva 2013/01/11 16:45:07 THis isn't being used in the .cc; I guess the fetc
zel 2013/01/11 19:51:16 Done.
152 content::NotificationRegistrar registrar_;
153 scoped_ptr<OAuth2TokenFetcher> oauth2_token_fetcher_;
154 scoped_ptr<OAuth2LoginVerifier> login_verifier_;
155 scoped_ptr<OAuth2PolicyFetcher> oauth2_policy_fetcher_;
156 std::string refresh_token_;
157
158 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager);
159 };
160
161
162 // OAuth1 specialization of OAuthLoginManager.
163 // TODO(zelidrag): Get rid of this one once we move everything to OAuth2.
164 class OAuth1LoginManager : public OAuthLoginManager,
165 public OAuth1TokenFetcher::Delegate,
166 public OAuth1LoginVerifier::Delegate {
167 public:
168 explicit OAuth1LoginManager(OAuthLoginManager::Delegate* delegate);
169
170 // OAuthLoginManager overrides.
171 virtual void RestorePolicyTokens(
172 net::URLRequestContextGetter* auth_request_context);
Joao da Silva 2013/01/11 16:45:07 OVERRIDE
zel 2013/01/11 19:51:16 Done.
173 virtual void RestoreSession(
174 Profile* user_profile,
175 net::URLRequestContextGetter* auth_request_context,
176 bool restore_from_auth_cookies) OVERRIDE;
177 virtual void ContinueSessionRestore() OVERRIDE;
178 virtual void Stop() OVERRIDE;
179
180 private:
181 // OAuth1TokenFetcher::Delegate overrides.
182 void OnOAuth1AccessTokenAvailable(const std::string& token,
183 const std::string& secret) OVERRIDE;
184 void OnOAuth1AccessTokenFetchFailed() OVERRIDE;
185
186 // OAuth1LoginVerifier::Delegate overrides.
187 virtual void OnOAuth1VerificationSucceeded(const std::string& user_name,
188 const std::string& sid,
189 const std::string& lsid,
190 const std::string& auth) OVERRIDE;
191 virtual void OnOAuth1VerificationFailed(
192 const std::string& user_name) OVERRIDE;
193
194 // Reads OAuth1 token from user profile's prefs.
195 bool ReadOAuth1Tokens();
196 // Stores OAuth1 token + secret in profile's prefs.
197 void StoreOAuth1Tokens();
198 // Fetch user credentials (sid/lsid) from |oauth1_token_| and
199 // |oauth1_secret_|.
200 void FetchCredentialsWithOAuth1();
201 // Verifies OAuth1 token by performing OAuthLogin and fetching credentials.
202 void VerifyOAuth1AccessToken();
203 // Starts fetching device policy tokens.
204 void FetchPolicyTokens();
205
206 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_;
207 scoped_ptr<OAuth1LoginVerifier> oauth1_login_verifier_;
208 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_;
209 std::string oauth1_token_;
210 std::string oauth1_secret_;
211
212 DISALLOW_COPY_AND_ASSIGN(OAuth1LoginManager);
213 };
214
215 } // namespace chromeos
216
217 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_LOGIN_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698