| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 5 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
| 6 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 6 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 const std::string& info_key); | 82 const std::string& info_key); |
| 83 | 83 |
| 84 // Start a TokenAuth request to pre-login the user with the given credentials. | 84 // Start a TokenAuth request to pre-login the user with the given credentials. |
| 85 void StartTokenAuth(const std::string& auth_token); | 85 void StartTokenAuth(const std::string& auth_token); |
| 86 | 86 |
| 87 // Start a MergeSession request to pre-login the user with the given | 87 // Start a MergeSession request to pre-login the user with the given |
| 88 // credentials. Unlike TokenAuth above, MergeSession will not sign out any | 88 // credentials. Unlike TokenAuth above, MergeSession will not sign out any |
| 89 // existing accounts. | 89 // existing accounts. |
| 90 void StartMergeSession(const std::string& auth_token); | 90 void StartMergeSession(const std::string& auth_token); |
| 91 | 91 |
| 92 // Start a request to get an uber-auth token. The given |access_token| must |
| 93 // be an OAuth2 valid access token. |
| 94 void StartUberAuthTokenFetch(const std::string& access_token); |
| 95 |
| 92 // Implementation of content::URLFetcherDelegate | 96 // Implementation of content::URLFetcherDelegate |
| 93 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 97 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| 94 | 98 |
| 95 // StartClientLogin been called && results not back yet? | 99 // StartClientLogin been called && results not back yet? |
| 96 bool HasPendingFetch(); | 100 bool HasPendingFetch(); |
| 97 | 101 |
| 98 // Stop any URL fetches in progress. | 102 // Stop any URL fetches in progress. |
| 99 void CancelRequest(); | 103 void CancelRequest(); |
| 100 | 104 |
| 101 // From a URLFetcher result, generate an appropriate error. | 105 // From a URLFetcher result, generate an appropriate error. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 // The format of the POST body to get OAuth2 auth code from auth token. | 124 // The format of the POST body to get OAuth2 auth code from auth token. |
| 121 static const char kClientLoginToOAuth2BodyFormat[]; | 125 static const char kClientLoginToOAuth2BodyFormat[]; |
| 122 // The format of the POST body to get OAuth2 token pair from auth code. | 126 // The format of the POST body to get OAuth2 token pair from auth code. |
| 123 static const char kOAuth2CodeToTokenPairBodyFormat[]; | 127 static const char kOAuth2CodeToTokenPairBodyFormat[]; |
| 124 // The format of the POST body for GetUserInfo. | 128 // The format of the POST body for GetUserInfo. |
| 125 static const char kGetUserInfoFormat[]; | 129 static const char kGetUserInfoFormat[]; |
| 126 // The format of the POST body for TokenAuth. | 130 // The format of the POST body for TokenAuth. |
| 127 static const char kTokenAuthFormat[]; | 131 static const char kTokenAuthFormat[]; |
| 128 // The format of the POST body for MergeSession. | 132 // The format of the POST body for MergeSession. |
| 129 static const char kMergeSessionFormat[]; | 133 static const char kMergeSessionFormat[]; |
| 134 // The format of the URL for UberAuthToken. |
| 135 static const char kUberAuthTokenURLFormat[]; |
| 130 | 136 |
| 131 // Constants for parsing ClientLogin errors. | 137 // Constants for parsing ClientLogin errors. |
| 132 static const char kAccountDeletedError[]; | 138 static const char kAccountDeletedError[]; |
| 133 static const char kAccountDeletedErrorCode[]; | 139 static const char kAccountDeletedErrorCode[]; |
| 134 static const char kAccountDisabledError[]; | 140 static const char kAccountDisabledError[]; |
| 135 static const char kAccountDisabledErrorCode[]; | 141 static const char kAccountDisabledErrorCode[]; |
| 136 static const char kBadAuthenticationError[]; | 142 static const char kBadAuthenticationError[]; |
| 137 static const char kBadAuthenticationErrorCode[]; | 143 static const char kBadAuthenticationErrorCode[]; |
| 138 static const char kCaptchaError[]; | 144 static const char kCaptchaError[]; |
| 139 static const char kCaptchaErrorCode[]; | 145 static const char kCaptchaErrorCode[]; |
| 140 static const char kServiceUnavailableError[]; | 146 static const char kServiceUnavailableError[]; |
| 141 static const char kServiceUnavailableErrorCode[]; | 147 static const char kServiceUnavailableErrorCode[]; |
| 142 static const char kErrorParam[]; | 148 static const char kErrorParam[]; |
| 143 static const char kErrorUrlParam[]; | 149 static const char kErrorUrlParam[]; |
| 144 static const char kCaptchaUrlParam[]; | 150 static const char kCaptchaUrlParam[]; |
| 145 static const char kCaptchaTokenParam[]; | 151 static const char kCaptchaTokenParam[]; |
| 146 | 152 |
| 147 // Constants for request/response for OAuth2 requests. | 153 // Constants for request/response for OAuth2 requests. |
| 148 static const char kAuthHeaderFormat[]; | 154 static const char kAuthHeaderFormat[]; |
| 155 static const char kOAuthHeaderFormat[]; |
| 149 static const char kClientLoginToOAuth2CookiePartSecure[]; | 156 static const char kClientLoginToOAuth2CookiePartSecure[]; |
| 150 static const char kClientLoginToOAuth2CookiePartHttpOnly[]; | 157 static const char kClientLoginToOAuth2CookiePartHttpOnly[]; |
| 151 static const char kClientLoginToOAuth2CookiePartCodePrefix[]; | 158 static const char kClientLoginToOAuth2CookiePartCodePrefix[]; |
| 152 static const int kClientLoginToOAuth2CookiePartCodePrefixLength; | 159 static const int kClientLoginToOAuth2CookiePartCodePrefixLength; |
| 153 static const char kOAuth2RefreshTokenKey[]; | 160 static const char kOAuth2RefreshTokenKey[]; |
| 154 static const char kOAuth2AccessTokenKey[]; | 161 static const char kOAuth2AccessTokenKey[]; |
| 155 static const char kOAuth2ExpiresInKey[]; | 162 static const char kOAuth2ExpiresInKey[]; |
| 156 | 163 |
| 157 // Process the results of a ClientLogin fetch. | 164 // Process the results of a ClientLogin fetch. |
| 158 void OnClientLoginFetched(const std::string& data, | 165 void OnClientLoginFetched(const std::string& data, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 177 int response_code); | 184 int response_code); |
| 178 | 185 |
| 179 void OnTokenAuthFetched(const std::string& data, | 186 void OnTokenAuthFetched(const std::string& data, |
| 180 const net::URLRequestStatus& status, | 187 const net::URLRequestStatus& status, |
| 181 int response_code); | 188 int response_code); |
| 182 | 189 |
| 183 void OnMergeSessionFetched(const std::string& data, | 190 void OnMergeSessionFetched(const std::string& data, |
| 184 const net::URLRequestStatus& status, | 191 const net::URLRequestStatus& status, |
| 185 int response_code); | 192 int response_code); |
| 186 | 193 |
| 194 void OnUberAuthTokenFetch(const std::string& data, |
| 195 const net::URLRequestStatus& status, |
| 196 int response_code); |
| 197 |
| 187 // Tokenize the results of a ClientLogin fetch. | 198 // Tokenize the results of a ClientLogin fetch. |
| 188 static void ParseClientLoginResponse(const std::string& data, | 199 static void ParseClientLoginResponse(const std::string& data, |
| 189 std::string* sid, | 200 std::string* sid, |
| 190 std::string* lsid, | 201 std::string* lsid, |
| 191 std::string* token); | 202 std::string* token); |
| 192 | 203 |
| 193 static void ParseClientLoginFailure(const std::string& data, | 204 static void ParseClientLoginFailure(const std::string& data, |
| 194 std::string* error, | 205 std::string* error, |
| 195 std::string* error_url, | 206 std::string* error_url, |
| 196 std::string* captcha_url, | 207 std::string* captcha_url, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 GaiaAuthConsumer* const consumer_; | 280 GaiaAuthConsumer* const consumer_; |
| 270 net::URLRequestContextGetter* const getter_; | 281 net::URLRequestContextGetter* const getter_; |
| 271 std::string source_; | 282 std::string source_; |
| 272 const GURL client_login_gurl_; | 283 const GURL client_login_gurl_; |
| 273 const GURL issue_auth_token_gurl_; | 284 const GURL issue_auth_token_gurl_; |
| 274 const GURL client_login_to_oauth2_gurl_; | 285 const GURL client_login_to_oauth2_gurl_; |
| 275 const GURL oauth2_token_gurl_; | 286 const GURL oauth2_token_gurl_; |
| 276 const GURL get_user_info_gurl_; | 287 const GURL get_user_info_gurl_; |
| 277 const GURL token_auth_gurl_; | 288 const GURL token_auth_gurl_; |
| 278 const GURL merge_session_gurl_; | 289 const GURL merge_session_gurl_; |
| 290 const GURL uberauth_token_gurl_; |
| 279 | 291 |
| 280 // While a fetch is going on: | 292 // While a fetch is going on: |
| 281 scoped_ptr<content::URLFetcher> fetcher_; | 293 scoped_ptr<content::URLFetcher> fetcher_; |
| 282 std::string request_body_; | 294 std::string request_body_; |
| 283 std::string requested_service_; // Currently tracked for IssueAuthToken only | 295 std::string requested_service_; // Currently tracked for IssueAuthToken only |
| 284 std::string requested_info_key_; // Currently tracked for GetUserInfo only | 296 std::string requested_info_key_; // Currently tracked for GetUserInfo only |
| 285 bool fetch_pending_; | 297 bool fetch_pending_; |
| 286 | 298 |
| 287 friend class GaiaAuthFetcherTest; | 299 friend class GaiaAuthFetcherTest; |
| 288 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); | 300 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); |
| 289 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError); | 301 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError); |
| 290 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError); | 302 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError); |
| 291 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); | 303 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); |
| 292 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); | 304 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); |
| 293 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); | 305 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); |
| 294 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); | 306 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); |
| 295 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); | 307 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); |
| 296 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); | 308 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); |
| 297 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, | 309 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, |
| 298 ParseClientLoginToOAuth2Response); | 310 ParseClientLoginToOAuth2Response); |
| 299 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ParseOAuth2TokenPairResponse); | 311 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ParseOAuth2TokenPairResponse); |
| 300 | 312 |
| 301 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); | 313 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); |
| 302 }; | 314 }; |
| 303 | 315 |
| 304 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 316 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
| OLD | NEW |