| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const std::string& lsid, | 61 const std::string& lsid, |
| 62 const char* const service); | 62 const char* const service); |
| 63 | 63 |
| 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. |
| 72 void StartTokenAuth(const std::string& auth_token); |
| 73 |
| 71 // Implementation of URLFetcher::Delegate | 74 // Implementation of URLFetcher::Delegate |
| 72 virtual void OnURLFetchComplete(const URLFetcher* source, | 75 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 73 const GURL& url, | 76 const GURL& url, |
| 74 const net::URLRequestStatus& status, | 77 const net::URLRequestStatus& status, |
| 75 int response_code, | 78 int response_code, |
| 76 const net::ResponseCookies& cookies, | 79 const net::ResponseCookies& cookies, |
| 77 const std::string& data); | 80 const std::string& data); |
| 78 | 81 |
| 79 // StartClientLogin been called && results not back yet? | 82 // StartClientLogin been called && results not back yet? |
| 80 bool HasPendingFetch(); | 83 bool HasPendingFetch(); |
| 81 | 84 |
| 82 // Stop any URL fetches in progress. | 85 // Stop any URL fetches in progress. |
| 83 void CancelRequest(); | 86 void CancelRequest(); |
| 84 | 87 |
| 85 private: | 88 private: |
| 86 // ClientLogin body constants that don't change | 89 // ClientLogin body constants that don't change |
| 87 static const char kCookiePersistence[]; | 90 static const char kCookiePersistence[]; |
| 88 static const char kAccountTypeHostedOrGoogle[]; | 91 static const char kAccountTypeHostedOrGoogle[]; |
| 89 static const char kAccountTypeGoogle[]; | 92 static const char kAccountTypeGoogle[]; |
| 90 | 93 |
| 91 // The format of the POST body for ClientLogin. | 94 // The format of the POST body for ClientLogin. |
| 92 static const char kClientLoginFormat[]; | 95 static const char kClientLoginFormat[]; |
| 93 // The format of said POST body when CAPTCHA token & answer are specified. | 96 // The format of said POST body when CAPTCHA token & answer are specified. |
| 94 static const char kClientLoginCaptchaFormat[]; | 97 static const char kClientLoginCaptchaFormat[]; |
| 95 // The format of the POST body for IssueAuthToken. | 98 // The format of the POST body for IssueAuthToken. |
| 96 static const char kIssueAuthTokenFormat[]; | 99 static const char kIssueAuthTokenFormat[]; |
| 97 // The format of the POSt body for GetUserInfo. | 100 // The format of the POST body for GetUserInfo. |
| 98 static const char kGetUserInfoFormat[]; | 101 static const char kGetUserInfoFormat[]; |
| 102 // The format of the POST body for TokenAuth. |
| 103 static const char kTokenAuthFormat[]; |
| 99 | 104 |
| 100 // Constants for parsing ClientLogin errors. | 105 // Constants for parsing ClientLogin errors. |
| 101 static const char kAccountDeletedError[]; | 106 static const char kAccountDeletedError[]; |
| 102 static const char kAccountDisabledError[]; | 107 static const char kAccountDisabledError[]; |
| 103 static const char kBadAuthenticationError[]; | 108 static const char kBadAuthenticationError[]; |
| 104 static const char kCaptchaError[]; | 109 static const char kCaptchaError[]; |
| 105 static const char kServiceUnavailableError[]; | 110 static const char kServiceUnavailableError[]; |
| 106 static const char kErrorParam[]; | 111 static const char kErrorParam[]; |
| 107 static const char kErrorUrlParam[]; | 112 static const char kErrorUrlParam[]; |
| 108 static const char kCaptchaUrlParam[]; | 113 static const char kCaptchaUrlParam[]; |
| 109 static const char kCaptchaTokenParam[]; | 114 static const char kCaptchaTokenParam[]; |
| 110 | 115 |
| 111 // Process the results of a ClientLogin fetch. | 116 // Process the results of a ClientLogin fetch. |
| 112 void OnClientLoginFetched(const std::string& data, | 117 void OnClientLoginFetched(const std::string& data, |
| 113 const net::URLRequestStatus& status, | 118 const net::URLRequestStatus& status, |
| 114 int response_code); | 119 int response_code); |
| 115 | 120 |
| 116 void OnIssueAuthTokenFetched(const std::string& data, | 121 void OnIssueAuthTokenFetched(const std::string& data, |
| 117 const net::URLRequestStatus& status, | 122 const net::URLRequestStatus& status, |
| 118 int response_code); | 123 int response_code); |
| 119 | 124 |
| 120 void OnGetUserInfoFetched(const std::string& data, | 125 void OnGetUserInfoFetched(const std::string& data, |
| 121 const net::URLRequestStatus& status, | 126 const net::URLRequestStatus& status, |
| 122 int response_code); | 127 int response_code); |
| 123 | 128 |
| 129 void OnTokenAuthFetched(const std::string& data, |
| 130 const net::URLRequestStatus& status, |
| 131 int response_code); |
| 132 |
| 124 // Tokenize the results of a ClientLogin fetch. | 133 // Tokenize the results of a ClientLogin fetch. |
| 125 static void ParseClientLoginResponse(const std::string& data, | 134 static void ParseClientLoginResponse(const std::string& data, |
| 126 std::string* sid, | 135 std::string* sid, |
| 127 std::string* lsid, | 136 std::string* lsid, |
| 128 std::string* token); | 137 std::string* token); |
| 129 | 138 |
| 130 static void ParseClientLoginFailure(const std::string& data, | 139 static void ParseClientLoginFailure(const std::string& data, |
| 131 std::string* error, | 140 std::string* error, |
| 132 std::string* error_url, | 141 std::string* error_url, |
| 133 std::string* captcha_url, | 142 std::string* captcha_url, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 154 HostedAccountsSetting allow_hosted_accounts); | 163 HostedAccountsSetting allow_hosted_accounts); |
| 155 // Supply the sid / lsid returned from ClientLogin in order to | 164 // Supply the sid / lsid returned from ClientLogin in order to |
| 156 // request a long lived auth token for a service. | 165 // request a long lived auth token for a service. |
| 157 static std::string MakeIssueAuthTokenBody(const std::string& sid, | 166 static std::string MakeIssueAuthTokenBody(const std::string& sid, |
| 158 const std::string& lsid, | 167 const std::string& lsid, |
| 159 const char* const service); | 168 const char* const service); |
| 160 // Supply the lsid returned from ClientLogin in order to fetch | 169 // Supply the lsid returned from ClientLogin in order to fetch |
| 161 // user information. | 170 // user information. |
| 162 static std::string MakeGetUserInfoBody(const std::string& lsid); | 171 static std::string MakeGetUserInfoBody(const std::string& lsid); |
| 163 | 172 |
| 173 // Supply the authentication token returned from StartIssueAuthToken. |
| 174 static std::string MakeTokenAuthBody(const std::string& auth_token, |
| 175 const std::string& continue_url, |
| 176 const std::string& source); |
| 177 |
| 164 // Create a fetcher useable for making any Gaia request. | 178 // Create a fetcher useable for making any Gaia request. |
| 165 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, | 179 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, |
| 166 const std::string& body, | 180 const std::string& body, |
| 167 const GURL& gaia_gurl_, | 181 const GURL& gaia_gurl_, |
| 168 URLFetcher::Delegate* delegate); | 182 URLFetcher::Delegate* delegate); |
| 169 | 183 |
| 170 | 184 |
| 171 // These fields are common to GaiaAuthFetcher, same every request | 185 // These fields are common to GaiaAuthFetcher, same every request |
| 172 GaiaAuthConsumer* const consumer_; | 186 GaiaAuthConsumer* const consumer_; |
| 173 net::URLRequestContextGetter* const getter_; | 187 net::URLRequestContextGetter* const getter_; |
| 174 std::string source_; | 188 std::string source_; |
| 175 const GURL client_login_gurl_; | 189 const GURL client_login_gurl_; |
| 176 const GURL issue_auth_token_gurl_; | 190 const GURL issue_auth_token_gurl_; |
| 177 const GURL get_user_info_gurl_; | 191 const GURL get_user_info_gurl_; |
| 192 const GURL token_auth_gurl_; |
| 178 | 193 |
| 179 // While a fetch is going on: | 194 // While a fetch is going on: |
| 180 scoped_ptr<URLFetcher> fetcher_; | 195 scoped_ptr<URLFetcher> fetcher_; |
| 181 std::string request_body_; | 196 std::string request_body_; |
| 182 std::string requested_service_; // Currently tracked for IssueAuthToken only | 197 std::string requested_service_; // Currently tracked for IssueAuthToken only |
| 183 std::string requested_info_key_; // Currently tracked for GetUserInfo only | 198 std::string requested_info_key_; // Currently tracked for GetUserInfo only |
| 184 bool fetch_pending_; | 199 bool fetch_pending_; |
| 185 | 200 |
| 186 friend class GaiaAuthFetcherTest; | 201 friend class GaiaAuthFetcherTest; |
| 187 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); | 202 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); |
| 188 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError); | 203 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError); |
| 189 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError); | 204 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError); |
| 190 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); | 205 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); |
| 191 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); | 206 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); |
| 192 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); | 207 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); |
| 193 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); | 208 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); |
| 194 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); | 209 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); |
| 195 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); | 210 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); |
| 196 | 211 |
| 197 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); | 212 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); |
| 198 }; | 213 }; |
| 199 | 214 |
| 200 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 215 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
| OLD | NEW |