| OLD | NEW |
| (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_OAUTH2_LOGIN_VERIFIER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_LOGIN_VERIFIER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/callback_forward.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 15 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 16 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
| 17 #include "google_apis/gaia/oauth2_access_token_fetcher.h" |
| 18 |
| 19 namespace net { |
| 20 class URLRequestContextGetter; |
| 21 } |
| 22 |
| 23 namespace chromeos { |
| 24 |
| 25 // Given the OAuth2 refresh token, this class will try to exchange it for GAIA |
| 26 // credentials (SID+LSID) and populate current session's cookie jar. |
| 27 class OAuth2LoginVerifier : public base::SupportsWeakPtr<OAuth2LoginVerifier>, |
| 28 public GaiaAuthConsumer, |
| 29 public OAuth2AccessTokenConsumer { |
| 30 public: |
| 31 class Delegate { |
| 32 public: |
| 33 virtual ~Delegate() {} |
| 34 // Invoked during exchange of OAuth2 refresh token for GAIA service token. |
| 35 virtual void OnOAuthLoginSuccess( |
| 36 const ClientLoginResult& gaia_credentials) = 0; |
| 37 // Invoked when provided OAuth2 refresh token is invalid. |
| 38 virtual void OnOAuthLoginFailure() = 0; |
| 39 // Invoked when cookie session is successfully merged. |
| 40 virtual void OnSessionMergeSuccess() = 0; |
| 41 // Invoked when cookie session can not be merged. |
| 42 virtual void OnSessionMergeFailure() = 0; |
| 43 }; |
| 44 |
| 45 OAuth2LoginVerifier(OAuth2LoginVerifier::Delegate* delegate, |
| 46 net::URLRequestContextGetter* system_request_context, |
| 47 net::URLRequestContextGetter* user_request_context); |
| 48 virtual ~OAuth2LoginVerifier(); |
| 49 |
| 50 // Starts reconstruction of client session cookies by first trying to |
| 51 // use stored |gaia_token|. If that fails, it will try to mint a new GAIA |
| 52 // token through OAuthLogin from the provided |oauth2_refresh_token|. |
| 53 void VerifyTokens(const std::string& oauth2_refresh_token, |
| 54 const std::string& gaia_token); |
| 55 |
| 56 private: |
| 57 enum SessionRestoreType { |
| 58 RESTORE_UNDEFINED = 0, |
| 59 RESTORE_FROM_GAIA_TOKEN = 1, |
| 60 RESTORE_FROM_OAUTH2_REFRESH_TOKEN = 2, |
| 61 }; |
| 62 // GaiaAuthConsumer overrides. |
| 63 virtual void OnUberAuthTokenSuccess(const std::string& token) OVERRIDE; |
| 64 virtual void OnUberAuthTokenFailure( |
| 65 const GoogleServiceAuthError& error) OVERRIDE; |
| 66 virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; |
| 67 virtual void OnClientLoginFailure( |
| 68 const GoogleServiceAuthError& error) OVERRIDE; |
| 69 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE; |
| 70 virtual void OnMergeSessionFailure( |
| 71 const GoogleServiceAuthError& error) OVERRIDE; |
| 72 |
| 73 // OAuth2AccessTokenConsumer overrides. |
| 74 virtual void OnGetTokenSuccess(const std::string& access_token, |
| 75 const base::Time& expiration_time) OVERRIDE; |
| 76 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
| 77 |
| 78 // Attempts to restore session from OAuth2 refresh token minting all necesarry |
| 79 // tokens along the way (OAuth2 access token, SID/LSID, GAIA service token). |
| 80 void RestoreSessionFromOAuth2RefreshToken(); |
| 81 |
| 82 // Attempts to restore session directly from GAIA service token. |
| 83 void RestoreSessionFromGaiaToken(); |
| 84 |
| 85 // Starts fetching OAuth1 access token for OAuthLogin call. |
| 86 void StartFetchingOAuthLoginAccessToken(); |
| 87 |
| 88 // Starts OAuthLogin request for GAIA uber-token. |
| 89 void StartOAuthLoginForUberToken(); |
| 90 |
| 91 // Starts OAuthLogin request. |
| 92 void StartOAuthLoginForGaiaCredentials(); |
| 93 |
| 94 // Attempts to merge session from present |gaia_token_|. |
| 95 void StartMergeSession(); |
| 96 |
| 97 // Decides how to proceed on GAIA |error|. If the error looks temporary, |
| 98 // retries |task| after certain delay until max retry count is reached. |
| 99 void RetryOnError(const char* operation_id, |
| 100 const GoogleServiceAuthError& error, |
| 101 const base::Closure& task_to_retry, |
| 102 const base::Closure& error_handler); |
| 103 |
| 104 OAuth2LoginVerifier::Delegate* delegate_; |
| 105 OAuth2AccessTokenFetcher token_fetcher_; |
| 106 GaiaAuthFetcher gaia_system_fetcher_; |
| 107 GaiaAuthFetcher gaia_fetcher_; |
| 108 ClientLoginResult gaia_credentials_; |
| 109 std::string access_token_; |
| 110 std::string refresh_token_; |
| 111 std::string gaia_token_; |
| 112 // The retry counter. Increment this only when failure happened. |
| 113 int retry_count_; |
| 114 SessionRestoreType type_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginVerifier); |
| 117 }; |
| 118 |
| 119 } // namespace chromeos |
| 120 |
| 121 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_LOGIN_VERIFIER_H_ |
| OLD | NEW |