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_mint_token_fetcher.h" | 5 #include "google_apis/gaia/oauth2_mint_token_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 // static | 158 // static |
159 GURL OAuth2MintTokenFetcher::MakeMintTokenUrl() { | 159 GURL OAuth2MintTokenFetcher::MakeMintTokenUrl() { |
160 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url()); | 160 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url()); |
161 } | 161 } |
162 | 162 |
163 // static | 163 // static |
164 std::string OAuth2MintTokenFetcher::MakeMintTokenHeader( | 164 std::string OAuth2MintTokenFetcher::MakeMintTokenHeader( |
165 const std::string& access_token) { | 165 const std::string& access_token) { |
166 return StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()); | 166 return base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()); |
167 } | 167 } |
168 | 168 |
169 // static | 169 // static |
170 std::string OAuth2MintTokenFetcher::MakeMintTokenBody( | 170 std::string OAuth2MintTokenFetcher::MakeMintTokenBody( |
171 const std::string& client_id, | 171 const std::string& client_id, |
172 const std::vector<std::string>& scopes, | 172 const std::vector<std::string>& scopes, |
173 const std::string& origin) { | 173 const std::string& origin) { |
174 return StringPrintf( | 174 return base::StringPrintf( |
175 kOAuth2IssueTokenBodyFormat, | 175 kOAuth2IssueTokenBodyFormat, |
176 net::EscapeUrlEncodedData(JoinString(scopes, ','), true).c_str(), | 176 net::EscapeUrlEncodedData(JoinString(scopes, ','), true).c_str(), |
177 net::EscapeUrlEncodedData(client_id, true).c_str(), | 177 net::EscapeUrlEncodedData(client_id, true).c_str(), |
178 net::EscapeUrlEncodedData(origin, true).c_str()); | 178 net::EscapeUrlEncodedData(origin, true).c_str()); |
179 } | 179 } |
180 | 180 |
181 // static | 181 // static |
182 bool OAuth2MintTokenFetcher::ParseMintTokenResponse( | 182 bool OAuth2MintTokenFetcher::ParseMintTokenResponse( |
183 const net::URLFetcher* source, | 183 const net::URLFetcher* source, |
184 std::string* access_token) { | 184 std::string* access_token) { |
185 CHECK(source); | 185 CHECK(source); |
186 CHECK(access_token); | 186 CHECK(access_token); |
187 std::string data; | 187 std::string data; |
188 source->GetResponseAsString(&data); | 188 source->GetResponseAsString(&data); |
189 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 189 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
190 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 190 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
191 return false; | 191 return false; |
192 | 192 |
193 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 193 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
194 return dict->GetString(kAccessTokenKey, access_token); | 194 return dict->GetString(kAccessTokenKey, access_token); |
195 } | 195 } |
OLD | NEW |