| 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 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 5 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 // static | 137 // static |
| 138 std::string GaiaAuthFetcher::MakeClientLoginBody( | 138 std::string GaiaAuthFetcher::MakeClientLoginBody( |
| 139 const std::string& username, | 139 const std::string& username, |
| 140 const std::string& password, | 140 const std::string& password, |
| 141 const std::string& source, | 141 const std::string& source, |
| 142 const char* service, | 142 const char* service, |
| 143 const std::string& login_token, | 143 const std::string& login_token, |
| 144 const std::string& login_captcha, | 144 const std::string& login_captcha, |
| 145 HostedAccountsSetting allow_hosted_accounts) { | 145 HostedAccountsSetting allow_hosted_accounts) { |
| 146 std::string encoded_username = EscapeUrlEncodedData(username, true); | 146 std::string encoded_username = EscapeUrlEncodedData(username); |
| 147 std::string encoded_password = EscapeUrlEncodedData(password, true); | 147 std::string encoded_password = EscapeUrlEncodedData(password); |
| 148 std::string encoded_login_token = EscapeUrlEncodedData(login_token, true); | 148 std::string encoded_login_token = EscapeUrlEncodedData(login_token); |
| 149 std::string encoded_login_captcha = EscapeUrlEncodedData(login_captcha, true); | 149 std::string encoded_login_captcha = EscapeUrlEncodedData(login_captcha); |
| 150 | 150 |
| 151 const char* account_type = allow_hosted_accounts == HostedAccountsAllowed ? | 151 const char* account_type = allow_hosted_accounts == HostedAccountsAllowed ? |
| 152 kAccountTypeHostedOrGoogle : | 152 kAccountTypeHostedOrGoogle : |
| 153 kAccountTypeGoogle; | 153 kAccountTypeGoogle; |
| 154 | 154 |
| 155 if (login_token.empty() || login_captcha.empty()) { | 155 if (login_token.empty() || login_captcha.empty()) { |
| 156 return base::StringPrintf(kClientLoginFormat, | 156 return base::StringPrintf(kClientLoginFormat, |
| 157 encoded_username.c_str(), | 157 encoded_username.c_str(), |
| 158 encoded_password.c_str(), | 158 encoded_password.c_str(), |
| 159 kCookiePersistence, | 159 kCookiePersistence, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 encoded_login_token.c_str(), | 172 encoded_login_token.c_str(), |
| 173 encoded_login_captcha.c_str()); | 173 encoded_login_captcha.c_str()); |
| 174 | 174 |
| 175 } | 175 } |
| 176 | 176 |
| 177 // static | 177 // static |
| 178 std::string GaiaAuthFetcher::MakeIssueAuthTokenBody( | 178 std::string GaiaAuthFetcher::MakeIssueAuthTokenBody( |
| 179 const std::string& sid, | 179 const std::string& sid, |
| 180 const std::string& lsid, | 180 const std::string& lsid, |
| 181 const char* const service) { | 181 const char* const service) { |
| 182 std::string encoded_sid = EscapeUrlEncodedData(sid, true); | 182 std::string encoded_sid = EscapeUrlEncodedData(sid); |
| 183 std::string encoded_lsid = EscapeUrlEncodedData(lsid, true); | 183 std::string encoded_lsid = EscapeUrlEncodedData(lsid); |
| 184 | 184 |
| 185 // All tokens should be session tokens except the gaia auth token. | 185 // All tokens should be session tokens except the gaia auth token. |
| 186 bool session = true; | 186 bool session = true; |
| 187 if (!strcmp(service, GaiaConstants::kGaiaService)) | 187 if (!strcmp(service, GaiaConstants::kGaiaService)) |
| 188 session = false; | 188 session = false; |
| 189 | 189 |
| 190 return base::StringPrintf(kIssueAuthTokenFormat, | 190 return base::StringPrintf(kIssueAuthTokenFormat, |
| 191 encoded_sid.c_str(), | 191 encoded_sid.c_str(), |
| 192 encoded_lsid.c_str(), | 192 encoded_lsid.c_str(), |
| 193 service, | 193 service, |
| 194 session ? "true" : "false"); | 194 session ? "true" : "false"); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // static | 197 // static |
| 198 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { | 198 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { |
| 199 std::string encoded_lsid = EscapeUrlEncodedData(lsid, true); | 199 std::string encoded_lsid = EscapeUrlEncodedData(lsid); |
| 200 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str()); | 200 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Helper method that extracts tokens from a successful reply. | 203 // Helper method that extracts tokens from a successful reply. |
| 204 // static | 204 // static |
| 205 void GaiaAuthFetcher::ParseClientLoginResponse(const std::string& data, | 205 void GaiaAuthFetcher::ParseClientLoginResponse(const std::string& data, |
| 206 std::string* sid, | 206 std::string* sid, |
| 207 std::string* lsid, | 207 std::string* lsid, |
| 208 std::string* token) { | 208 std::string* token) { |
| 209 using std::vector; | 209 using std::vector; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 NOTREACHED(); | 435 NOTREACHED(); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 // static | 439 // static |
| 440 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 440 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
| 441 const std::string& alleged_error) { | 441 const std::string& alleged_error) { |
| 442 return alleged_error.find(kSecondFactor) != | 442 return alleged_error.find(kSecondFactor) != |
| 443 std::string::npos; | 443 std::string::npos; |
| 444 } | 444 } |
| OLD | NEW |