| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Start a request to get a particular key from user info. | 64 // Start a request to get a particular key from user info. |
| 65 // GaiaAuthConsumer will be called back on the same thread when | 65 // GaiaAuthConsumer will be called back on the same thread when |
| 66 // results come back. | 66 // results come back. |
| 67 // You can't make more than one request at a time. | 67 // You can't make more than one request at a time. |
| 68 void StartGetUserInfo(const std::string& lsid, | 68 void StartGetUserInfo(const std::string& lsid, |
| 69 const std::string& info_key); | 69 const std::string& info_key); |
| 70 | 70 |
| 71 // Start a TokenAuth request to pre-login the user with the given credentials. | 71 // Start a TokenAuth request to pre-login the user with the given credentials. |
| 72 void StartTokenAuth(const std::string& auth_token); | 72 void StartTokenAuth(const std::string& auth_token); |
| 73 | 73 |
| 74 // Start a MergeSession request to pre-login the user with the given |
| 75 // credentials. Unlike TokenAuth above, MergeSession will not sign out any |
| 76 // existing accounts. |
| 77 void StartMergeSession(const std::string& auth_token); |
| 78 |
| 74 // Implementation of URLFetcher::Delegate | 79 // Implementation of URLFetcher::Delegate |
| 75 virtual void OnURLFetchComplete(const URLFetcher* source, | 80 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 76 const GURL& url, | 81 const GURL& url, |
| 77 const net::URLRequestStatus& status, | 82 const net::URLRequestStatus& status, |
| 78 int response_code, | 83 int response_code, |
| 79 const net::ResponseCookies& cookies, | 84 const net::ResponseCookies& cookies, |
| 80 const std::string& data); | 85 const std::string& data); |
| 81 | 86 |
| 82 // StartClientLogin been called && results not back yet? | 87 // StartClientLogin been called && results not back yet? |
| 83 bool HasPendingFetch(); | 88 bool HasPendingFetch(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 101 // The format of the POST body for ClientLogin. | 106 // The format of the POST body for ClientLogin. |
| 102 static const char kClientLoginFormat[]; | 107 static const char kClientLoginFormat[]; |
| 103 // The format of said POST body when CAPTCHA token & answer are specified. | 108 // The format of said POST body when CAPTCHA token & answer are specified. |
| 104 static const char kClientLoginCaptchaFormat[]; | 109 static const char kClientLoginCaptchaFormat[]; |
| 105 // The format of the POST body for IssueAuthToken. | 110 // The format of the POST body for IssueAuthToken. |
| 106 static const char kIssueAuthTokenFormat[]; | 111 static const char kIssueAuthTokenFormat[]; |
| 107 // The format of the POST body for GetUserInfo. | 112 // The format of the POST body for GetUserInfo. |
| 108 static const char kGetUserInfoFormat[]; | 113 static const char kGetUserInfoFormat[]; |
| 109 // The format of the POST body for TokenAuth. | 114 // The format of the POST body for TokenAuth. |
| 110 static const char kTokenAuthFormat[]; | 115 static const char kTokenAuthFormat[]; |
| 116 // The format of the POST body for MergeSession. |
| 117 static const char kMergeSessionFormat[]; |
| 111 | 118 |
| 112 // Constants for parsing ClientLogin errors. | 119 // Constants for parsing ClientLogin errors. |
| 113 static const char kAccountDeletedError[]; | 120 static const char kAccountDeletedError[]; |
| 114 static const char kAccountDeletedErrorCode[]; | 121 static const char kAccountDeletedErrorCode[]; |
| 115 static const char kAccountDisabledError[]; | 122 static const char kAccountDisabledError[]; |
| 116 static const char kAccountDisabledErrorCode[]; | 123 static const char kAccountDisabledErrorCode[]; |
| 117 static const char kBadAuthenticationError[]; | 124 static const char kBadAuthenticationError[]; |
| 118 static const char kBadAuthenticationErrorCode[]; | 125 static const char kBadAuthenticationErrorCode[]; |
| 119 static const char kCaptchaError[]; | 126 static const char kCaptchaError[]; |
| 120 static const char kCaptchaErrorCode[]; | 127 static const char kCaptchaErrorCode[]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 int response_code); | 142 int response_code); |
| 136 | 143 |
| 137 void OnGetUserInfoFetched(const std::string& data, | 144 void OnGetUserInfoFetched(const std::string& data, |
| 138 const net::URLRequestStatus& status, | 145 const net::URLRequestStatus& status, |
| 139 int response_code); | 146 int response_code); |
| 140 | 147 |
| 141 void OnTokenAuthFetched(const std::string& data, | 148 void OnTokenAuthFetched(const std::string& data, |
| 142 const net::URLRequestStatus& status, | 149 const net::URLRequestStatus& status, |
| 143 int response_code); | 150 int response_code); |
| 144 | 151 |
| 152 void OnMergeSessionFetched(const std::string& data, |
| 153 const net::URLRequestStatus& status, |
| 154 int response_code); |
| 155 |
| 145 // Tokenize the results of a ClientLogin fetch. | 156 // Tokenize the results of a ClientLogin fetch. |
| 146 static void ParseClientLoginResponse(const std::string& data, | 157 static void ParseClientLoginResponse(const std::string& data, |
| 147 std::string* sid, | 158 std::string* sid, |
| 148 std::string* lsid, | 159 std::string* lsid, |
| 149 std::string* token); | 160 std::string* token); |
| 150 | 161 |
| 151 static void ParseClientLoginFailure(const std::string& data, | 162 static void ParseClientLoginFailure(const std::string& data, |
| 152 std::string* error, | 163 std::string* error, |
| 153 std::string* error_url, | 164 std::string* error_url, |
| 154 std::string* captcha_url, | 165 std::string* captcha_url, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 173 const char* const service); | 184 const char* const service); |
| 174 // Supply the lsid returned from ClientLogin in order to fetch | 185 // Supply the lsid returned from ClientLogin in order to fetch |
| 175 // user information. | 186 // user information. |
| 176 static std::string MakeGetUserInfoBody(const std::string& lsid); | 187 static std::string MakeGetUserInfoBody(const std::string& lsid); |
| 177 | 188 |
| 178 // Supply the authentication token returned from StartIssueAuthToken. | 189 // Supply the authentication token returned from StartIssueAuthToken. |
| 179 static std::string MakeTokenAuthBody(const std::string& auth_token, | 190 static std::string MakeTokenAuthBody(const std::string& auth_token, |
| 180 const std::string& continue_url, | 191 const std::string& continue_url, |
| 181 const std::string& source); | 192 const std::string& source); |
| 182 | 193 |
| 194 // Supply the authentication token returned from StartIssueAuthToken. |
| 195 static std::string MakeMergeSessionBody(const std::string& auth_token, |
| 196 const std::string& continue_url, |
| 197 const std::string& source); |
| 198 |
| 183 // Create a fetcher useable for making any Gaia request. | 199 // Create a fetcher useable for making any Gaia request. |
| 184 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, | 200 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, |
| 185 const std::string& body, | 201 const std::string& body, |
| 186 const GURL& gaia_gurl_, | 202 const GURL& gaia_gurl, |
| 203 bool send_cookies, |
| 187 URLFetcher::Delegate* delegate); | 204 URLFetcher::Delegate* delegate); |
| 188 | 205 |
| 189 // From a URLFetcher result, generate an appropriate error. | 206 // From a URLFetcher result, generate an appropriate error. |
| 190 // From the API documentation, both IssueAuthToken and ClientLogin have | 207 // From the API documentation, both IssueAuthToken and ClientLogin have |
| 191 // the same error returns. | 208 // the same error returns. |
| 192 static GoogleServiceAuthError GenerateAuthError( | 209 static GoogleServiceAuthError GenerateAuthError( |
| 193 const std::string& data, | 210 const std::string& data, |
| 194 const net::URLRequestStatus& status); | 211 const net::URLRequestStatus& status); |
| 195 | 212 |
| 196 // These fields are common to GaiaAuthFetcher, same every request | 213 // These fields are common to GaiaAuthFetcher, same every request |
| 197 GaiaAuthConsumer* const consumer_; | 214 GaiaAuthConsumer* const consumer_; |
| 198 net::URLRequestContextGetter* const getter_; | 215 net::URLRequestContextGetter* const getter_; |
| 199 std::string source_; | 216 std::string source_; |
| 200 const GURL client_login_gurl_; | 217 const GURL client_login_gurl_; |
| 201 const GURL issue_auth_token_gurl_; | 218 const GURL issue_auth_token_gurl_; |
| 202 const GURL get_user_info_gurl_; | 219 const GURL get_user_info_gurl_; |
| 203 const GURL token_auth_gurl_; | 220 const GURL token_auth_gurl_; |
| 221 const GURL merge_session_gurl_; |
| 204 | 222 |
| 205 // While a fetch is going on: | 223 // While a fetch is going on: |
| 206 scoped_ptr<URLFetcher> fetcher_; | 224 scoped_ptr<URLFetcher> fetcher_; |
| 207 std::string request_body_; | 225 std::string request_body_; |
| 208 std::string requested_service_; // Currently tracked for IssueAuthToken only | 226 std::string requested_service_; // Currently tracked for IssueAuthToken only |
| 209 std::string requested_info_key_; // Currently tracked for GetUserInfo only | 227 std::string requested_info_key_; // Currently tracked for GetUserInfo only |
| 210 bool fetch_pending_; | 228 bool fetch_pending_; |
| 211 | 229 |
| 212 friend class GaiaAuthFetcherTest; | 230 friend class GaiaAuthFetcherTest; |
| 213 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); | 231 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); |
| 214 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError); | 232 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError); |
| 215 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError); | 233 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError); |
| 216 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); | 234 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); |
| 217 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); | 235 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); |
| 218 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); | 236 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); |
| 219 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); | 237 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); |
| 220 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); | 238 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); |
| 221 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); | 239 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); |
| 222 | 240 |
| 223 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); | 241 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); |
| 224 }; | 242 }; |
| 225 | 243 |
| 226 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 244 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
| OLD | NEW |