Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: google_apis/gaia/fake_gaia.cc

Issue 108663008: Additional OAuth2 tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« google_apis/gaia/fake_gaia.h ('K') | « google_apis/gaia/fake_gaia.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/linked_ptr.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "google_apis/gaia/gaia_urls.h" 21 #include "google_apis/gaia/gaia_urls.h"
21 #include "net/base/url_util.h" 22 #include "net/base/url_util.h"
23 #include "net/cookies/parsed_cookie.h"
22 #include "net/http/http_status_code.h" 24 #include "net/http/http_status_code.h"
23 #include "net/test/embedded_test_server/http_request.h" 25 #include "net/test/embedded_test_server/http_request.h"
24 #include "net/test/embedded_test_server/http_response.h" 26 #include "net/test/embedded_test_server/http_response.h"
25 #include "url/url_parse.h" 27 #include "url/url_parse.h"
26 28
27 #define REGISTER_RESPONSE_HANDLER(url, method) \ 29 #define REGISTER_RESPONSE_HANDLER(url, method) \
28 request_handlers_.insert(std::make_pair( \ 30 request_handlers_.insert(std::make_pair( \
29 url.path(), base::Bind(&FakeGaia::method, base::Unretained(this)))) 31 url.path(), base::Bind(&FakeGaia::method, base::Unretained(this))))
30 32
31 using namespace net::test_server; 33 using namespace net::test_server;
32 34
33 namespace { 35 namespace {
34 36
35 const base::FilePath::CharType kServiceLogin[] = 37 const base::FilePath::CharType kServiceLogin[] =
36 FILE_PATH_LITERAL("google_apis/test/service_login.html"); 38 FILE_PATH_LITERAL("google_apis/test/service_login.html");
37 39
38 // OAuth2 Authentication header value prefix. 40 // OAuth2 Authentication header value prefix.
39 const char kAuthHeaderBearer[] = "Bearer "; 41 const char kAuthHeaderBearer[] = "Bearer ";
40 const char kAuthHeaderOAuth[] = "OAuth "; 42 const char kAuthHeaderOAuth[] = "OAuth ";
41 43
44 typedef std::map<std::string, std::string> CookieMap;
45
46 // Parses cookie name-value map our of |request|.
47 CookieMap GetRequestCookies(const HttpRequest& request) {
48 CookieMap result;
49 std::map<std::string, std::string>::const_iterator iter =
50 request.headers.find("Cookie");
51 if (iter != request.headers.end()) {
52 std::vector<std::string> cookie_nv_pairs;
53 base::SplitString(iter->second, ' ', &cookie_nv_pairs);
54 for(std::vector<std::string>::const_iterator cookie_line =
55 cookie_nv_pairs.begin();
56 cookie_line != cookie_nv_pairs.end();
57 ++cookie_line) {
58 std::vector<std::string> name_value;
59 base::SplitString(*cookie_line, '=', &name_value);
60 if (name_value.size() != 2)
61 continue;
62
63 std::string value = name_value[1];
64 if (value.size() && value[value.size() - 1] == ';')
65 value = value.substr(0, value.size() -1);
66
67 result.insert(std::make_pair(name_value[0], value));
68 }
69 }
70 return result;
71 }
72
73 // Extracts the parameter named |key| from |query| and places it in |value|.
74 // Returns false if no parameter is found.
75 bool GetQueryParameter(const std::string& query,
76 const std::string& key,
77 std::string* value) {
78 // Name and scheme actually don't matter, but are required to get a valid URL
79 // for parsing.
80 GURL query_url("http://localhost?" + query);
81 return net::GetValueForKeyInQuery(query_url, key, value);
82 }
83
84 // Extracts the |access_token| from authorization header of |request|.
85 bool GetAccessToken(const HttpRequest& request,
86 const char* auth_token_prefix,
87 std::string* access_token) {
88 std::map<std::string, std::string>::const_iterator auth_header_entry =
89 request.headers.find("Authorization");
90 if (auth_header_entry != request.headers.end()) {
91 if (StartsWithASCII(auth_header_entry->second, auth_token_prefix, true)) {
92 *access_token = auth_header_entry->second.substr(
93 strlen(auth_token_prefix));
94 return true;
95 }
96 }
97
98 return false;
99 }
100
42 } 101 }
43 102
44 FakeGaia::AccessTokenInfo::AccessTokenInfo() 103 FakeGaia::AccessTokenInfo::AccessTokenInfo()
45 : expires_in(3600) {} 104 : expires_in(3600) {}
46 105
47 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {} 106 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {}
48 107
49 FakeGaia::FakeGaia() { 108 FakeGaia::FakeGaia() {
50 base::FilePath source_root_dir; 109 base::FilePath source_root_dir;
51 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); 110 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir);
52 CHECK(base::ReadFileToString( 111 CHECK(base::ReadFileToString(
53 source_root_dir.Append(base::FilePath(kServiceLogin)), 112 source_root_dir.Append(base::FilePath(kServiceLogin)),
54 &service_login_response_)); 113 &service_login_response_));
55 } 114 }
56 115
57 FakeGaia::~FakeGaia() {} 116 FakeGaia::~FakeGaia() {}
58 117
59 void FakeGaia::SetAuthTokens(const std::string& auth_code, 118 void FakeGaia::SetMergeSessionParams(
60 const std::string& refresh_token, 119 const MergeSessionParams& params) {
61 const std::string& access_token, 120 merge_session_params_ = params;
62 const std::string& gaia_uber_token,
63 const std::string& session_sid_cookie,
64 const std::string& session_lsid_cookie) {
65 fake_auth_code_ = auth_code;
66 fake_refresh_token_ = refresh_token;
67 fake_access_token_ = access_token;
68 fake_gaia_uber_token_ = gaia_uber_token;
69 fake_session_sid_cookie_ = session_sid_cookie;
70 fake_session_lsid_cookie_ = session_lsid_cookie;
71 } 121 }
72 122
73 void FakeGaia::Initialize() { 123 void FakeGaia::Initialize() {
74 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 124 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
75 // Handles /ServiceLogin GAIA call. 125 // Handles /ServiceLogin GAIA call.
76 REGISTER_RESPONSE_HANDLER( 126 REGISTER_RESPONSE_HANDLER(
77 gaia_urls->service_login_url(), HandleServiceLogin); 127 gaia_urls->service_login_url(), HandleServiceLogin);
78 128
79 // Handles /ServiceLoginAuth GAIA call. 129 // Handles /ServiceLoginAuth GAIA call.
80 REGISTER_RESPONSE_HANDLER( 130 REGISTER_RESPONSE_HANDLER(
(...skipping 20 matching lines...) Expand all
101 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); 151 gaia_urls->oauth2_issue_token_url(), HandleIssueToken);
102 152
103 // Handles /oauth2/v2/tokeninfo GAIA call. 153 // Handles /oauth2/v2/tokeninfo GAIA call.
104 REGISTER_RESPONSE_HANDLER( 154 REGISTER_RESPONSE_HANDLER(
105 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); 155 gaia_urls->oauth2_token_info_url(), HandleTokenInfo);
106 } 156 }
107 157
108 void FakeGaia::HandleProgramaticAuth( 158 void FakeGaia::HandleProgramaticAuth(
109 const HttpRequest& request, 159 const HttpRequest& request,
110 BasicHttpResponse* http_response) { 160 BasicHttpResponse* http_response) {
161 http_response->set_code(net::HTTP_UNAUTHORIZED);
162 if (merge_session_params_.auth_code.empty()) {
163 http_response->set_code(net::HTTP_BAD_REQUEST);
164 return;
165 }
166
111 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 167 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
112 std::string scope; 168 std::string scope;
113 if (!GetQueryParameter(request.content, "scope", &scope) || 169 if (!GetQueryParameter(request.content, "scope", &scope) ||
114 gaia_urls->oauth1_login_scope() != scope) { 170 gaia_urls->oauth1_login_scope() != scope) {
115 http_response->set_code(net::HTTP_BAD_REQUEST); 171 return;
172 }
173
174 CookieMap cookies = GetRequestCookies(request);
175 CookieMap::const_iterator sid_iter = cookies.find("SID");
176 if (sid_iter == cookies.end() ||
177 sid_iter->second != merge_session_params_.auth_sid_cookie) {
178 LOG(ERROR) << "/o/oauth2/programmatic_auth missing SID cookie";
179 return;
180 }
181 CookieMap::const_iterator lsid_iter = cookies.find("LSID");
182 if (lsid_iter == cookies.end() ||
183 lsid_iter->second != merge_session_params_.auth_lsid_cookie) {
184 LOG(ERROR) << "/o/oauth2/programmatic_auth missing LSID cookie";
116 return; 185 return;
117 } 186 }
118 187
119 std::string client_id; 188 std::string client_id;
120 if (!GetQueryParameter(request.content, "client_id", &client_id) || 189 if (!GetQueryParameter(request.content, "client_id", &client_id) ||
121 gaia_urls->oauth2_chrome_client_id() != client_id) { 190 gaia_urls->oauth2_chrome_client_id() != client_id) {
122 http_response->set_code(net::HTTP_BAD_REQUEST);
123 return; 191 return;
124 } 192 }
125 193
126 http_response->AddCustomHeader( 194 http_response->AddCustomHeader(
127 "Set-Cookie", 195 "Set-Cookie",
128 base::StringPrintf( 196 base::StringPrintf(
129 "oauth_code=%s; Path=/o/GetOAuth2Token; Secure; HttpOnly;", 197 "oauth_code=%s; Path=/o/GetOAuth2Token; Secure; HttpOnly;",
130 fake_auth_code_.c_str())); 198 merge_session_params_.auth_code.c_str()));
131 http_response->set_code(net::HTTP_OK); 199 http_response->set_code(net::HTTP_OK);
132 http_response->set_content_type("text/html"); 200 http_response->set_content_type("text/html");
133 } 201 }
134 202
135 void FakeGaia::HandleServiceLogin(const HttpRequest& request, 203 void FakeGaia::HandleServiceLogin(const HttpRequest& request,
136 BasicHttpResponse* http_response) { 204 BasicHttpResponse* http_response) {
137 http_response->set_code(net::HTTP_OK); 205 http_response->set_code(net::HTTP_OK);
138 http_response->set_content(service_login_response_); 206 http_response->set_content(service_login_response_);
139 http_response->set_content_type("text/html"); 207 http_response->set_content_type("text/html");
140 } 208 }
141 209
142 void FakeGaia::HandleOAuthLogin(const HttpRequest& request, 210 void FakeGaia::HandleOAuthLogin(const HttpRequest& request,
143 BasicHttpResponse* http_response) { 211 BasicHttpResponse* http_response) {
144 http_response->set_code(net::HTTP_BAD_REQUEST); 212 http_response->set_code(net::HTTP_UNAUTHORIZED);
213 if (merge_session_params_.gaia_uber_token.empty()) {
214 http_response->set_code(net::HTTP_FORBIDDEN);
215 return;
216 }
217
145 std::string access_token; 218 std::string access_token;
146 if (!GetAccessToken(request, kAuthHeaderOAuth, &access_token)) { 219 if (!GetAccessToken(request, kAuthHeaderOAuth, &access_token)) {
147 LOG(ERROR) << "/OAuthLogin missing access token in the header"; 220 LOG(ERROR) << "/OAuthLogin missing access token in the header";
148 return; 221 return;
149 } 222 }
150 223
151 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); 224 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
152 std::string request_query = request_url.query(); 225 std::string request_query = request_url.query();
153 226
154 std::string source; 227 std::string source;
155 if (!GetQueryParameter(request_query, "source", &source)) { 228 if (!GetQueryParameter(request_query, "source", &source)) {
156 LOG(ERROR) << "Missing 'source' param in /OAuthLogin call"; 229 LOG(ERROR) << "Missing 'source' param in /OAuthLogin call";
157 return; 230 return;
158 } 231 }
159 232
160 std::string issue_uberauth; 233 std::string issue_uberauth;
161 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) && 234 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) &&
162 issue_uberauth == "1") { 235 issue_uberauth == "1") {
163 http_response->set_content(fake_gaia_uber_token_); 236 http_response->set_content(merge_session_params_.gaia_uber_token);
164 http_response->set_code(net::HTTP_OK); 237 http_response->set_code(net::HTTP_OK);
165 // Issue GAIA uber token. 238 // Issue GAIA uber token.
166 } else { 239 } else {
167 LOG(FATAL) << "/OAuthLogin for SID/LSID is not supported"; 240 LOG(FATAL) << "/OAuthLogin for SID/LSID is not supported";
168 } 241 }
169 } 242 }
170 243
171 void FakeGaia::HandleMergeSession(const HttpRequest& request, 244 void FakeGaia::HandleMergeSession(const HttpRequest& request,
172 BasicHttpResponse* http_response) { 245 BasicHttpResponse* http_response) {
173 http_response->set_code(net::HTTP_BAD_REQUEST); 246 http_response->set_code(net::HTTP_UNAUTHORIZED);
247 if (merge_session_params_.session_sid_cookie.empty() ||
248 merge_session_params_.session_lsid_cookie.empty()) {
249 http_response->set_code(net::HTTP_BAD_REQUEST);
250 return;
251 }
174 252
175 std::string uber_token; 253 std::string uber_token;
176 if (!GetQueryParameter(request.content, "uberauth", &uber_token) || 254 if (!GetQueryParameter(request.content, "uberauth", &uber_token) ||
177 uber_token != fake_gaia_uber_token_) { 255 uber_token != merge_session_params_.gaia_uber_token) {
178 LOG(ERROR) << "Missing or invalid 'uberauth' param in /MergeSession call"; 256 LOG(ERROR) << "Missing or invalid 'uberauth' param in /MergeSession call";
179 return; 257 return;
180 } 258 }
181 259
182 std::string continue_url; 260 std::string continue_url;
183 if (!GetQueryParameter(request.content, "continue", &continue_url)) { 261 if (!GetQueryParameter(request.content, "continue", &continue_url)) {
184 LOG(ERROR) << "Missing or invalid 'continue' param in /MergeSession call"; 262 LOG(ERROR) << "Missing or invalid 'continue' param in /MergeSession call";
185 return; 263 return;
186 } 264 }
187 265
188 std::string source; 266 std::string source;
189 if (!GetQueryParameter(request.content, "source", &source)) { 267 if (!GetQueryParameter(request.content, "source", &source)) {
190 LOG(ERROR) << "Missing or invalid 'source' param in /MergeSession call"; 268 LOG(ERROR) << "Missing or invalid 'source' param in /MergeSession call";
191 return; 269 return;
192 } 270 }
193 271
194 http_response->AddCustomHeader( 272 http_response->AddCustomHeader(
195 "Set-Cookie", 273 "Set-Cookie",
196 base::StringPrintf( 274 base::StringPrintf(
197 "SID=%s; LSID=%s; Path=/; Secure; HttpOnly;", 275 "SID=%s; Path=/; HttpOnly;",
198 fake_session_sid_cookie_.c_str(), 276 merge_session_params_.session_sid_cookie.c_str()));
199 fake_session_lsid_cookie_.c_str())); 277 http_response->AddCustomHeader(
278 "Set-Cookie",
279 base::StringPrintf(
280 "LSID=%s; Path=/; HttpOnly;",
281 merge_session_params_.session_lsid_cookie.c_str()));
200 // TODO(zelidrag): Not used now. 282 // TODO(zelidrag): Not used now.
201 http_response->set_content("OK"); 283 http_response->set_content("OK");
202 http_response->set_code(net::HTTP_OK); 284 http_response->set_code(net::HTTP_OK);
203 } 285 }
204 286
205 287
206 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, 288 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request,
207 BasicHttpResponse* http_response) { 289 BasicHttpResponse* http_response) {
208 std::string continue_url = 290 std::string continue_url =
209 GaiaUrls::GetInstance()->service_login_url().spec(); 291 GaiaUrls::GetInstance()->service_login_url().spec();
210 GetQueryParameter(request.content, "continue", &continue_url); 292 GetQueryParameter(request.content, "continue", &continue_url);
211 http_response->set_code(net::HTTP_OK); 293 http_response->set_code(net::HTTP_OK);
212 const std::string redirect_js = 294 const std::string redirect_js =
213 "document.location.href = '" + continue_url + "'"; 295 "document.location.href = '" + continue_url + "'";
296
297 if (!merge_session_params_.auth_sid_cookie.empty() &&
298 !merge_session_params_.auth_lsid_cookie.empty()) {
299 http_response->AddCustomHeader(
300 "Set-Cookie",
301 base::StringPrintf(
302 "SID=%s; Path=/; HttpOnly;",
303 merge_session_params_.auth_sid_cookie.c_str()));
304 http_response->AddCustomHeader(
305 "Set-Cookie",
306 base::StringPrintf(
307 "LSID=%s; Path=/; HttpOnly;",
308 merge_session_params_.auth_lsid_cookie.c_str()));
309 }
310
214 http_response->set_content( 311 http_response->set_content(
215 "<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>"); 312 "<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>");
216 http_response->set_content_type("text/html"); 313 http_response->set_content_type("text/html");
217 } 314 }
218 315
219 void FakeGaia::HandleAuthToken(const HttpRequest& request, 316 void FakeGaia::HandleAuthToken(const HttpRequest& request,
220 BasicHttpResponse* http_response) { 317 BasicHttpResponse* http_response) {
221 std::string grant_type; 318 std::string grant_type;
222 std::string refresh_token; 319 std::string refresh_token;
223 std::string client_id; 320 std::string client_id;
224 std::string scope; 321 std::string scope;
225 std::string auth_code; 322 std::string auth_code;
226 const AccessTokenInfo* token_info = NULL; 323 const AccessTokenInfo* token_info = NULL;
227 GetQueryParameter(request.content, "scope", &scope); 324 GetQueryParameter(request.content, "scope", &scope);
228 325
229 if (!GetQueryParameter(request.content, "grant_type", &grant_type)) { 326 if (!GetQueryParameter(request.content, "grant_type", &grant_type)) {
230 http_response->set_code(net::HTTP_BAD_REQUEST); 327 http_response->set_code(net::HTTP_BAD_REQUEST);
231 LOG(ERROR) << "No 'grant_type' param in /o/oauth2/token"; 328 LOG(ERROR) << "No 'grant_type' param in /o/oauth2/token";
232 return; 329 return;
233 } 330 }
234 331
235 if (grant_type == "authorization_code") { 332 if (grant_type == "authorization_code") {
236 if (!GetQueryParameter(request.content, "code", &auth_code) || 333 if (!GetQueryParameter(request.content, "code", &auth_code) ||
237 auth_code != fake_auth_code_) { 334 auth_code != merge_session_params_.auth_code) {
238 http_response->set_code(net::HTTP_BAD_REQUEST); 335 http_response->set_code(net::HTTP_BAD_REQUEST);
239 LOG(ERROR) << "No 'code' param in /o/oauth2/token"; 336 LOG(ERROR) << "No 'code' param in /o/oauth2/token";
240 return; 337 return;
241 } 338 }
242 339
243 if (GaiaUrls::GetInstance()->oauth1_login_scope() != scope) { 340 if (GaiaUrls::GetInstance()->oauth1_login_scope() != scope) {
244 http_response->set_code(net::HTTP_BAD_REQUEST); 341 http_response->set_code(net::HTTP_BAD_REQUEST);
245 LOG(ERROR) << "Invalid scope for /o/oauth2/token - " << scope; 342 LOG(ERROR) << "Invalid scope for /o/oauth2/token - " << scope;
246 return; 343 return;
247 } 344 }
248 345
249 base::DictionaryValue response_dict; 346 base::DictionaryValue response_dict;
250 response_dict.SetString("refresh_token", fake_refresh_token_); 347 response_dict.SetString("refresh_token",
251 response_dict.SetString("access_token", fake_access_token_); 348 merge_session_params_.refresh_token);
349 response_dict.SetString("access_token",
350 merge_session_params_.access_token);
252 response_dict.SetInteger("expires_in", 3600); 351 response_dict.SetInteger("expires_in", 3600);
253 FormatJSONResponse(response_dict, http_response); 352 FormatJSONResponse(response_dict, http_response);
254 } else if (GetQueryParameter(request.content, 353 } else if (GetQueryParameter(request.content,
255 "refresh_token", 354 "refresh_token",
256 &refresh_token) && 355 &refresh_token) &&
257 GetQueryParameter(request.content, 356 GetQueryParameter(request.content,
258 "client_id", 357 "client_id",
259 &client_id) && 358 &client_id) &&
260 (token_info = FindAccessTokenInfo(refresh_token, 359 (token_info = FindAccessTokenInfo(refresh_token,
261 client_id, 360 client_id,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 entry != access_token_info_map_.upper_bound(auth_token); 473 entry != access_token_info_map_.upper_bound(auth_token);
375 ++entry) { 474 ++entry) {
376 if (entry->second.audience == client_id && 475 if (entry->second.audience == client_id &&
377 (scope_string.empty() || entry->second.scopes == scopes)) { 476 (scope_string.empty() || entry->second.scopes == scopes)) {
378 return &(entry->second); 477 return &(entry->second);
379 } 478 }
380 } 479 }
381 480
382 return NULL; 481 return NULL;
383 } 482 }
384
385 // static
386 bool FakeGaia::GetQueryParameter(const std::string& query,
387 const std::string& key,
388 std::string* value) {
389 // Name and scheme actually don't matter, but are required to get a valid URL
390 // for parsing.
391 GURL query_url("http://localhost?" + query);
392 return net::GetValueForKeyInQuery(query_url, key, value);
393 }
394
395 // static
396 bool FakeGaia::GetAccessToken(const HttpRequest& request,
397 const char* auth_token_prefix,
398 std::string* access_token) {
399 std::map<std::string, std::string>::const_iterator auth_header_entry =
400 request.headers.find("Authorization");
401 if (auth_header_entry != request.headers.end()) {
402 if (StartsWithASCII(auth_header_entry->second, auth_token_prefix, true)) {
403 *access_token = auth_header_entry->second.substr(
404 strlen(auth_token_prefix));
405 return true;
406 }
407 }
408
409 return false;
410 }
OLDNEW
« google_apis/gaia/fake_gaia.h ('K') | « google_apis/gaia/fake_gaia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698