OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/oauth2_access_token_fetcher.h" | 5 #include "google_apis/gaia/oauth2_access_token_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 const std::string& client_id, | 181 const std::string& client_id, |
182 const std::string& client_secret, | 182 const std::string& client_secret, |
183 const std::string& refresh_token, | 183 const std::string& refresh_token, |
184 const std::vector<std::string>& scopes) { | 184 const std::vector<std::string>& scopes) { |
185 std::string enc_client_id = net::EscapeUrlEncodedData(client_id, true); | 185 std::string enc_client_id = net::EscapeUrlEncodedData(client_id, true); |
186 std::string enc_client_secret = | 186 std::string enc_client_secret = |
187 net::EscapeUrlEncodedData(client_secret, true); | 187 net::EscapeUrlEncodedData(client_secret, true); |
188 std::string enc_refresh_token = | 188 std::string enc_refresh_token = |
189 net::EscapeUrlEncodedData(refresh_token, true); | 189 net::EscapeUrlEncodedData(refresh_token, true); |
190 if (scopes.empty()) { | 190 if (scopes.empty()) { |
191 return StringPrintf( | 191 return base::StringPrintf( |
192 kGetAccessTokenBodyFormat, | 192 kGetAccessTokenBodyFormat, |
193 enc_client_id.c_str(), | 193 enc_client_id.c_str(), |
194 enc_client_secret.c_str(), | 194 enc_client_secret.c_str(), |
195 enc_refresh_token.c_str()); | 195 enc_refresh_token.c_str()); |
196 } else { | 196 } else { |
197 std::string scopes_string = JoinString(scopes, ' '); | 197 std::string scopes_string = JoinString(scopes, ' '); |
198 return StringPrintf( | 198 return base::StringPrintf( |
199 kGetAccessTokenBodyWithScopeFormat, | 199 kGetAccessTokenBodyWithScopeFormat, |
200 enc_client_id.c_str(), | 200 enc_client_id.c_str(), |
201 enc_client_secret.c_str(), | 201 enc_client_secret.c_str(), |
202 enc_refresh_token.c_str(), | 202 enc_refresh_token.c_str(), |
203 net::EscapeUrlEncodedData(scopes_string, true).c_str()); | 203 net::EscapeUrlEncodedData(scopes_string, true).c_str()); |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 // static | 207 // static |
208 bool OAuth2AccessTokenFetcher::ParseGetAccessTokenResponse( | 208 bool OAuth2AccessTokenFetcher::ParseGetAccessTokenResponse( |
209 const net::URLFetcher* source, | 209 const net::URLFetcher* source, |
210 std::string* access_token, | 210 std::string* access_token, |
211 int* expires_in) { | 211 int* expires_in) { |
212 CHECK(source); | 212 CHECK(source); |
213 CHECK(access_token); | 213 CHECK(access_token); |
214 std::string data; | 214 std::string data; |
215 source->GetResponseAsString(&data); | 215 source->GetResponseAsString(&data); |
216 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 216 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
217 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 217 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
218 return false; | 218 return false; |
219 | 219 |
220 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 220 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
221 return dict->GetString(kAccessTokenKey, access_token) && | 221 return dict->GetString(kAccessTokenKey, access_token) && |
222 dict->GetInteger(kExpiresInKey, expires_in); | 222 dict->GetInteger(kExpiresInKey, expires_in); |
223 } | 223 } |
OLD | NEW |