OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "google_apis/gaia/fake_gaia.h" | 5 #include "google_apis/gaia/fake_gaia.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (StartsWithASCII(auth_header_entry->second, auth_token_prefix, true)) { | 86 if (StartsWithASCII(auth_header_entry->second, auth_token_prefix, true)) { |
87 *access_token = auth_header_entry->second.substr( | 87 *access_token = auth_header_entry->second.substr( |
88 strlen(auth_token_prefix)); | 88 strlen(auth_token_prefix)); |
89 return true; | 89 return true; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 return false; | 93 return false; |
94 } | 94 } |
95 | 95 |
| 96 void SetCookies(BasicHttpResponse* http_response, |
| 97 const std::string& sid_cookie, |
| 98 const std::string& lsid_cookie) { |
| 99 http_response->AddCustomHeader( |
| 100 "Set-Cookie", |
| 101 base::StringPrintf("SID=%s; Path=/; HttpOnly;", sid_cookie.c_str())); |
| 102 http_response->AddCustomHeader( |
| 103 "Set-Cookie", |
| 104 base::StringPrintf("LSID=%s; Path=/; HttpOnly;", lsid_cookie.c_str())); |
96 } | 105 } |
97 | 106 |
| 107 } // namespace |
| 108 |
98 FakeGaia::AccessTokenInfo::AccessTokenInfo() | 109 FakeGaia::AccessTokenInfo::AccessTokenInfo() |
99 : expires_in(3600) {} | 110 : expires_in(3600) {} |
100 | 111 |
101 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {} | 112 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {} |
102 | 113 |
103 FakeGaia::MergeSessionParams::MergeSessionParams() { | 114 FakeGaia::MergeSessionParams::MergeSessionParams() { |
104 } | 115 } |
105 | 116 |
106 FakeGaia::MergeSessionParams::~MergeSessionParams() { | 117 FakeGaia::MergeSessionParams::~MergeSessionParams() { |
107 } | 118 } |
108 | 119 |
109 FakeGaia::FakeGaia() { | 120 FakeGaia::FakeGaia() { |
110 base::FilePath source_root_dir; | 121 base::FilePath source_root_dir; |
111 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); | 122 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); |
112 CHECK(base::ReadFileToString( | 123 CHECK(base::ReadFileToString( |
113 source_root_dir.Append(base::FilePath(kServiceLogin)), | 124 source_root_dir.Append(base::FilePath(kServiceLogin)), |
114 &service_login_response_)); | 125 &service_login_response_)); |
115 } | 126 } |
116 | 127 |
117 FakeGaia::~FakeGaia() {} | 128 FakeGaia::~FakeGaia() {} |
118 | 129 |
119 void FakeGaia::SetMergeSessionParams( | 130 void FakeGaia::SetMergeSessionParams( |
120 const MergeSessionParams& params) { | 131 const MergeSessionParams& params) { |
121 merge_session_params_ = params; | 132 merge_session_params_ = params; |
122 } | 133 } |
123 | 134 |
124 void FakeGaia::Initialize() { | 135 void FakeGaia::Initialize() { |
125 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 136 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
| 137 // Handles /MergeSession GAIA call. |
| 138 REGISTER_RESPONSE_HANDLER( |
| 139 gaia_urls->merge_session_url(), HandleMergeSession); |
| 140 |
| 141 // Handles /o/oauth2/programmatic_auth GAIA call. |
| 142 REGISTER_RESPONSE_HANDLER( |
| 143 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth); |
| 144 |
126 // Handles /ServiceLogin GAIA call. | 145 // Handles /ServiceLogin GAIA call. |
127 REGISTER_RESPONSE_HANDLER( | 146 REGISTER_RESPONSE_HANDLER( |
128 gaia_urls->service_login_url(), HandleServiceLogin); | 147 gaia_urls->service_login_url(), HandleServiceLogin); |
129 | 148 |
| 149 // Handles /OAuthLogin GAIA call. |
| 150 REGISTER_RESPONSE_HANDLER( |
| 151 gaia_urls->oauth1_login_url(), HandleOAuthLogin); |
| 152 |
130 // Handles /ServiceLoginAuth GAIA call. | 153 // Handles /ServiceLoginAuth GAIA call. |
131 REGISTER_RESPONSE_HANDLER( | 154 REGISTER_RESPONSE_HANDLER( |
132 gaia_urls->service_login_auth_url(), HandleServiceLoginAuth); | 155 gaia_urls->service_login_auth_url(), HandleServiceLoginAuth); |
133 | 156 |
134 // Handles /o/oauth2/programmatic_auth GAIA call. | 157 // Handles /SSO GAIA call (not GAIA, made up for SAML tests). |
135 REGISTER_RESPONSE_HANDLER( | 158 REGISTER_PATH_RESPONSE_HANDLER("/SSO", HandleSSO); |
136 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth); | |
137 | 159 |
138 // Handles /o/oauth2/token GAIA call. | 160 // Handles /o/oauth2/token GAIA call. |
139 REGISTER_RESPONSE_HANDLER( | 161 REGISTER_RESPONSE_HANDLER( |
140 gaia_urls->oauth2_token_url(), HandleAuthToken); | 162 gaia_urls->oauth2_token_url(), HandleAuthToken); |
141 | 163 |
142 // Handles /OAuthLogin GAIA call. | 164 // Handles /oauth2/v2/tokeninfo GAIA call. |
143 REGISTER_RESPONSE_HANDLER( | 165 REGISTER_RESPONSE_HANDLER( |
144 gaia_urls->oauth1_login_url(), HandleOAuthLogin); | 166 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); |
145 | |
146 // Handles /MergeSession GAIA call. | |
147 REGISTER_RESPONSE_HANDLER( | |
148 gaia_urls->merge_session_url(), HandleMergeSession); | |
149 | 167 |
150 // Handles /oauth2/v2/IssueToken GAIA call. | 168 // Handles /oauth2/v2/IssueToken GAIA call. |
151 REGISTER_RESPONSE_HANDLER( | 169 REGISTER_RESPONSE_HANDLER( |
152 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); | 170 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); |
153 | 171 |
154 // Handles /oauth2/v2/tokeninfo GAIA call. | 172 // Handles /GetUserInfo GAIA call. |
155 REGISTER_RESPONSE_HANDLER( | 173 REGISTER_RESPONSE_HANDLER( |
156 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); | 174 gaia_urls->get_user_info_url(), HandleGetUserInfo); |
| 175 } |
157 | 176 |
158 // Handles /SSO GAIA call (not GAIA, made up for SAML tests). | 177 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { |
159 REGISTER_PATH_RESPONSE_HANDLER("/SSO", HandleSSO); | 178 // The scheme and host of the URL is actually not important but required to |
| 179 // get a valid GURL in order to parse |request.relative_url|. |
| 180 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); |
| 181 std::string request_path = request_url.path(); |
| 182 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| 183 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); |
| 184 if (iter != request_handlers_.end()) { |
| 185 LOG(WARNING) << "Serving request " << request_path; |
| 186 iter->second.Run(request, http_response.get()); |
| 187 } else { |
| 188 LOG(ERROR) << "Unhandled request " << request_path; |
| 189 return scoped_ptr<HttpResponse>(); // Request not understood. |
| 190 } |
| 191 |
| 192 return http_response.PassAs<HttpResponse>(); |
| 193 } |
| 194 |
| 195 void FakeGaia::IssueOAuthToken(const std::string& auth_token, |
| 196 const AccessTokenInfo& token_info) { |
| 197 access_token_info_map_.insert(std::make_pair(auth_token, token_info)); |
| 198 } |
| 199 |
| 200 void FakeGaia::RegisterSamlUser(const std::string& account_id, |
| 201 const GURL& saml_idp) { |
| 202 saml_account_idp_map_[account_id] = saml_idp; |
| 203 } |
| 204 |
| 205 // static |
| 206 bool FakeGaia::GetQueryParameter(const std::string& query, |
| 207 const std::string& key, |
| 208 std::string* value) { |
| 209 // Name and scheme actually don't matter, but are required to get a valid URL |
| 210 // for parsing. |
| 211 GURL query_url("http://localhost?" + query); |
| 212 return net::GetValueForKeyInQuery(query_url, key, value); |
| 213 } |
| 214 |
| 215 void FakeGaia::HandleMergeSession(const HttpRequest& request, |
| 216 BasicHttpResponse* http_response) { |
| 217 http_response->set_code(net::HTTP_UNAUTHORIZED); |
| 218 if (merge_session_params_.session_sid_cookie.empty() || |
| 219 merge_session_params_.session_lsid_cookie.empty()) { |
| 220 http_response->set_code(net::HTTP_BAD_REQUEST); |
| 221 return; |
| 222 } |
| 223 |
| 224 std::string uber_token; |
| 225 if (!GetQueryParameter(request.content, "uberauth", &uber_token) || |
| 226 uber_token != merge_session_params_.gaia_uber_token) { |
| 227 LOG(ERROR) << "Missing or invalid 'uberauth' param in /MergeSession call"; |
| 228 return; |
| 229 } |
| 230 |
| 231 std::string continue_url; |
| 232 if (!GetQueryParameter(request.content, "continue", &continue_url)) { |
| 233 LOG(ERROR) << "Missing or invalid 'continue' param in /MergeSession call"; |
| 234 return; |
| 235 } |
| 236 |
| 237 std::string source; |
| 238 if (!GetQueryParameter(request.content, "source", &source)) { |
| 239 LOG(ERROR) << "Missing or invalid 'source' param in /MergeSession call"; |
| 240 return; |
| 241 } |
| 242 |
| 243 SetCookies(http_response, |
| 244 merge_session_params_.session_sid_cookie, |
| 245 merge_session_params_.session_lsid_cookie); |
| 246 // TODO(zelidrag): Not used now. |
| 247 http_response->set_content("OK"); |
| 248 http_response->set_code(net::HTTP_OK); |
160 } | 249 } |
161 | 250 |
162 void FakeGaia::HandleProgramaticAuth( | 251 void FakeGaia::HandleProgramaticAuth( |
163 const HttpRequest& request, | 252 const HttpRequest& request, |
164 BasicHttpResponse* http_response) { | 253 BasicHttpResponse* http_response) { |
165 http_response->set_code(net::HTTP_UNAUTHORIZED); | 254 http_response->set_code(net::HTTP_UNAUTHORIZED); |
166 if (merge_session_params_.auth_code.empty()) { | 255 if (merge_session_params_.auth_code.empty()) { |
167 http_response->set_code(net::HTTP_BAD_REQUEST); | 256 http_response->set_code(net::HTTP_BAD_REQUEST); |
168 return; | 257 return; |
169 } | 258 } |
(...skipping 27 matching lines...) Expand all Loading... |
197 | 286 |
198 http_response->AddCustomHeader( | 287 http_response->AddCustomHeader( |
199 "Set-Cookie", | 288 "Set-Cookie", |
200 base::StringPrintf( | 289 base::StringPrintf( |
201 "oauth_code=%s; Path=/o/GetOAuth2Token; Secure; HttpOnly;", | 290 "oauth_code=%s; Path=/o/GetOAuth2Token; Secure; HttpOnly;", |
202 merge_session_params_.auth_code.c_str())); | 291 merge_session_params_.auth_code.c_str())); |
203 http_response->set_code(net::HTTP_OK); | 292 http_response->set_code(net::HTTP_OK); |
204 http_response->set_content_type("text/html"); | 293 http_response->set_content_type("text/html"); |
205 } | 294 } |
206 | 295 |
| 296 void FakeGaia::FormatJSONResponse(const base::DictionaryValue& response_dict, |
| 297 BasicHttpResponse* http_response) { |
| 298 std::string response_json; |
| 299 base::JSONWriter::Write(&response_dict, &response_json); |
| 300 http_response->set_content(response_json); |
| 301 http_response->set_code(net::HTTP_OK); |
| 302 } |
| 303 |
| 304 const FakeGaia::AccessTokenInfo* FakeGaia::FindAccessTokenInfo( |
| 305 const std::string& auth_token, |
| 306 const std::string& client_id, |
| 307 const std::string& scope_string) const { |
| 308 if (auth_token.empty() || client_id.empty()) |
| 309 return NULL; |
| 310 |
| 311 std::vector<std::string> scope_list; |
| 312 base::SplitString(scope_string, ' ', &scope_list); |
| 313 ScopeSet scopes(scope_list.begin(), scope_list.end()); |
| 314 |
| 315 for (AccessTokenInfoMap::const_iterator entry( |
| 316 access_token_info_map_.lower_bound(auth_token)); |
| 317 entry != access_token_info_map_.upper_bound(auth_token); |
| 318 ++entry) { |
| 319 if (entry->second.audience == client_id && |
| 320 (scope_string.empty() || entry->second.scopes == scopes)) { |
| 321 return &(entry->second); |
| 322 } |
| 323 } |
| 324 |
| 325 return NULL; |
| 326 } |
| 327 |
207 void FakeGaia::HandleServiceLogin(const HttpRequest& request, | 328 void FakeGaia::HandleServiceLogin(const HttpRequest& request, |
208 BasicHttpResponse* http_response) { | 329 BasicHttpResponse* http_response) { |
209 http_response->set_code(net::HTTP_OK); | 330 http_response->set_code(net::HTTP_OK); |
210 http_response->set_content(service_login_response_); | 331 http_response->set_content(service_login_response_); |
211 http_response->set_content_type("text/html"); | 332 http_response->set_content_type("text/html"); |
212 } | 333 } |
213 | 334 |
214 void FakeGaia::HandleOAuthLogin(const HttpRequest& request, | 335 void FakeGaia::HandleOAuthLogin(const HttpRequest& request, |
215 BasicHttpResponse* http_response) { | 336 BasicHttpResponse* http_response) { |
216 http_response->set_code(net::HTTP_UNAUTHORIZED); | 337 http_response->set_code(net::HTTP_UNAUTHORIZED); |
(...skipping 21 matching lines...) Expand all Loading... |
238 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) && | 359 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) && |
239 issue_uberauth == "1") { | 360 issue_uberauth == "1") { |
240 http_response->set_content(merge_session_params_.gaia_uber_token); | 361 http_response->set_content(merge_session_params_.gaia_uber_token); |
241 http_response->set_code(net::HTTP_OK); | 362 http_response->set_code(net::HTTP_OK); |
242 // Issue GAIA uber token. | 363 // Issue GAIA uber token. |
243 } else { | 364 } else { |
244 LOG(FATAL) << "/OAuthLogin for SID/LSID is not supported"; | 365 LOG(FATAL) << "/OAuthLogin for SID/LSID is not supported"; |
245 } | 366 } |
246 } | 367 } |
247 | 368 |
248 void FakeGaia::HandleMergeSession(const HttpRequest& request, | |
249 BasicHttpResponse* http_response) { | |
250 http_response->set_code(net::HTTP_UNAUTHORIZED); | |
251 if (merge_session_params_.session_sid_cookie.empty() || | |
252 merge_session_params_.session_lsid_cookie.empty()) { | |
253 http_response->set_code(net::HTTP_BAD_REQUEST); | |
254 return; | |
255 } | |
256 | |
257 std::string uber_token; | |
258 if (!GetQueryParameter(request.content, "uberauth", &uber_token) || | |
259 uber_token != merge_session_params_.gaia_uber_token) { | |
260 LOG(ERROR) << "Missing or invalid 'uberauth' param in /MergeSession call"; | |
261 return; | |
262 } | |
263 | |
264 std::string continue_url; | |
265 if (!GetQueryParameter(request.content, "continue", &continue_url)) { | |
266 LOG(ERROR) << "Missing or invalid 'continue' param in /MergeSession call"; | |
267 return; | |
268 } | |
269 | |
270 std::string source; | |
271 if (!GetQueryParameter(request.content, "source", &source)) { | |
272 LOG(ERROR) << "Missing or invalid 'source' param in /MergeSession call"; | |
273 return; | |
274 } | |
275 | |
276 http_response->AddCustomHeader( | |
277 "Set-Cookie", | |
278 base::StringPrintf( | |
279 "SID=%s; Path=/; HttpOnly;", | |
280 merge_session_params_.session_sid_cookie.c_str())); | |
281 http_response->AddCustomHeader( | |
282 "Set-Cookie", | |
283 base::StringPrintf( | |
284 "LSID=%s; Path=/; HttpOnly;", | |
285 merge_session_params_.session_lsid_cookie.c_str())); | |
286 // TODO(zelidrag): Not used now. | |
287 http_response->set_content("OK"); | |
288 http_response->set_code(net::HTTP_OK); | |
289 } | |
290 | |
291 | |
292 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, | 369 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, |
293 BasicHttpResponse* http_response) { | 370 BasicHttpResponse* http_response) { |
294 std::string continue_url = | 371 std::string continue_url = |
295 GaiaUrls::GetInstance()->service_login_url().spec(); | 372 GaiaUrls::GetInstance()->service_login_url().spec(); |
296 GetQueryParameter(request.content, "continue", &continue_url); | 373 GetQueryParameter(request.content, "continue", &continue_url); |
297 | 374 |
298 std::string redirect_url = continue_url; | 375 std::string redirect_url = continue_url; |
299 | 376 |
300 std::string email; | 377 std::string email; |
301 if (GetQueryParameter(request.content, "Email", &email) && | 378 if (GetQueryParameter(request.content, "Email", &email) && |
302 saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) { | 379 saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) { |
303 GURL url(saml_account_idp_map_[email]); | 380 GURL url(saml_account_idp_map_[email]); |
304 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request"); | 381 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request"); |
305 url = net::AppendQueryParameter(url, "RelayState", continue_url); | 382 url = net::AppendQueryParameter(url, "RelayState", continue_url); |
306 redirect_url = url.spec(); | 383 redirect_url = url.spec(); |
307 } | 384 } else if (!merge_session_params_.auth_sid_cookie.empty() && |
308 | 385 !merge_session_params_.auth_lsid_cookie.empty()) { |
309 if (!merge_session_params_.auth_sid_cookie.empty() && | 386 SetCookies(http_response, |
310 !merge_session_params_.auth_lsid_cookie.empty()) { | 387 merge_session_params_.auth_sid_cookie, |
311 http_response->AddCustomHeader( | 388 merge_session_params_.auth_lsid_cookie); |
312 "Set-Cookie", | |
313 base::StringPrintf( | |
314 "SID=%s; Path=/; HttpOnly;", | |
315 merge_session_params_.auth_sid_cookie.c_str())); | |
316 http_response->AddCustomHeader( | |
317 "Set-Cookie", | |
318 base::StringPrintf( | |
319 "LSID=%s; Path=/; HttpOnly;", | |
320 merge_session_params_.auth_lsid_cookie.c_str())); | |
321 } | 389 } |
322 | 390 |
323 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); | 391 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
324 http_response->AddCustomHeader("Location", redirect_url); | 392 http_response->AddCustomHeader("Location", redirect_url); |
325 } | 393 } |
326 | 394 |
327 void FakeGaia::HandleSSO(const HttpRequest& request, | 395 void FakeGaia::HandleSSO(const HttpRequest& request, |
328 BasicHttpResponse* http_response) { | 396 BasicHttpResponse* http_response) { |
| 397 if (!merge_session_params_.auth_sid_cookie.empty() && |
| 398 !merge_session_params_.auth_lsid_cookie.empty()) { |
| 399 SetCookies(http_response, |
| 400 merge_session_params_.auth_sid_cookie, |
| 401 merge_session_params_.auth_lsid_cookie); |
| 402 } |
329 std::string relay_state; | 403 std::string relay_state; |
330 GetQueryParameter(request.content, "RelayState", &relay_state); | 404 GetQueryParameter(request.content, "RelayState", &relay_state); |
331 std::string redirect_url = relay_state; | 405 std::string redirect_url = relay_state; |
332 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); | 406 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
333 http_response->AddCustomHeader("Location", redirect_url); | 407 http_response->AddCustomHeader("Location", redirect_url); |
334 } | 408 } |
335 | 409 |
336 void FakeGaia::HandleAuthToken(const HttpRequest& request, | 410 void FakeGaia::HandleAuthToken(const HttpRequest& request, |
337 BasicHttpResponse* http_response) { | 411 BasicHttpResponse* http_response) { |
338 std::string grant_type; | 412 std::string grant_type; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 response_dict.SetString("issueAdvice", "auto"); | 512 response_dict.SetString("issueAdvice", "auto"); |
439 response_dict.SetString("expiresIn", | 513 response_dict.SetString("expiresIn", |
440 base::IntToString(token_info->expires_in)); | 514 base::IntToString(token_info->expires_in)); |
441 response_dict.SetString("token", token_info->token); | 515 response_dict.SetString("token", token_info->token); |
442 FormatJSONResponse(response_dict, http_response); | 516 FormatJSONResponse(response_dict, http_response); |
443 } else { | 517 } else { |
444 http_response->set_code(net::HTTP_BAD_REQUEST); | 518 http_response->set_code(net::HTTP_BAD_REQUEST); |
445 } | 519 } |
446 } | 520 } |
447 | 521 |
448 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { | 522 void FakeGaia::HandleGetUserInfo(const HttpRequest& request, |
449 // The scheme and host of the URL is actually not important but required to | 523 BasicHttpResponse* http_response) { |
450 // get a valid GURL in order to parse |request.relative_url|. | 524 std::string lsid; |
451 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); | 525 if (!GetQueryParameter(request.content, "LSID", &lsid)) { |
452 std::string request_path = request_url.path(); | 526 http_response->set_code(net::HTTP_BAD_REQUEST); |
453 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); | 527 LOG(ERROR) << "/GetUserInfo missing LSID"; |
454 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); | 528 return; |
455 if (iter != request_handlers_.end()) { | |
456 LOG(WARNING) << "Serving request " << request_path; | |
457 iter->second.Run(request, http_response.get()); | |
458 } else { | |
459 LOG(ERROR) << "Unhandled request " << request_path; | |
460 return scoped_ptr<HttpResponse>(); // Request not understood. | |
461 } | 529 } |
462 | 530 if (lsid != merge_session_params_.auth_lsid_cookie) { |
463 return http_response.PassAs<HttpResponse>(); | 531 http_response->set_code(net::HTTP_BAD_REQUEST); |
464 } | 532 LOG(ERROR) << "/GetUserInfo contains unknown LSID"; |
465 | 533 return; |
466 void FakeGaia::IssueOAuthToken(const std::string& auth_token, | 534 } |
467 const AccessTokenInfo& token_info) { | 535 http_response->set_content(base::StringPrintf( |
468 access_token_info_map_.insert(std::make_pair(auth_token, token_info)); | 536 "email=%s", merge_session_params_.email.c_str())); |
469 } | |
470 | |
471 void FakeGaia::RegisterSamlUser(const std::string& account_id, | |
472 const GURL& saml_idp) { | |
473 saml_account_idp_map_[account_id] = saml_idp; | |
474 } | |
475 | |
476 void FakeGaia::FormatJSONResponse(const base::DictionaryValue& response_dict, | |
477 BasicHttpResponse* http_response) { | |
478 std::string response_json; | |
479 base::JSONWriter::Write(&response_dict, &response_json); | |
480 http_response->set_content(response_json); | |
481 http_response->set_code(net::HTTP_OK); | 537 http_response->set_code(net::HTTP_OK); |
482 } | 538 } |
483 | |
484 const FakeGaia::AccessTokenInfo* FakeGaia::FindAccessTokenInfo( | |
485 const std::string& auth_token, | |
486 const std::string& client_id, | |
487 const std::string& scope_string) const { | |
488 if (auth_token.empty() || client_id.empty()) | |
489 return NULL; | |
490 | |
491 std::vector<std::string> scope_list; | |
492 base::SplitString(scope_string, ' ', &scope_list); | |
493 ScopeSet scopes(scope_list.begin(), scope_list.end()); | |
494 | |
495 for (AccessTokenInfoMap::const_iterator entry( | |
496 access_token_info_map_.lower_bound(auth_token)); | |
497 entry != access_token_info_map_.upper_bound(auth_token); | |
498 ++entry) { | |
499 if (entry->second.audience == client_id && | |
500 (scope_string.empty() || entry->second.scopes == scopes)) { | |
501 return &(entry->second); | |
502 } | |
503 } | |
504 | |
505 return NULL; | |
506 } | |
507 | |
508 // static | |
509 bool FakeGaia::GetQueryParameter(const std::string& query, | |
510 const std::string& key, | |
511 std::string* value) { | |
512 // Name and scheme actually don't matter, but are required to get a valid URL | |
513 // for parsing. | |
514 GURL query_url("http://localhost?" + query); | |
515 return net::GetValueForKeyInQuery(query_url, key, value); | |
516 } | |
OLD | NEW |