| Index: chrome/common/net/gaia/oauth2_access_token_fetcher.cc
|
| ===================================================================
|
| --- chrome/common/net/gaia/oauth2_access_token_fetcher.cc (revision 111883)
|
| +++ chrome/common/net/gaia/oauth2_access_token_fetcher.cc (working copy)
|
| @@ -6,8 +6,10 @@
|
|
|
| #include <algorithm>
|
| #include <string>
|
| +#include <vector>
|
|
|
| #include "base/json/json_reader.h"
|
| +#include "base/string_util.h"
|
| #include "base/stringprintf.h"
|
| #include "base/values.h"
|
| #include "chrome/common/net/gaia/gaia_urls.h"
|
| @@ -27,10 +29,17 @@
|
| namespace {
|
| static const char kGetAccessTokenBodyFormat[] =
|
| "client_id=%s&"
|
| - "client_secret=%s"
|
| + "client_secret=%s&"
|
| "grant_type=refresh_token&"
|
| "refresh_token=%s";
|
|
|
| +static const char kGetAccessTokenBodyWithScopeFormat[] =
|
| + "client_id=%s&"
|
| + "client_secret=%s&"
|
| + "grant_type=refresh_token&"
|
| + "refresh_token=%s&"
|
| + "scope=%s";
|
| +
|
| static const char kAccessTokenKey[] = "access_token";
|
|
|
| static bool GetStringFromDictionary(const DictionaryValue* dict,
|
| @@ -96,10 +105,12 @@
|
|
|
| void OAuth2AccessTokenFetcher::Start(const std::string& client_id,
|
| const std::string& client_secret,
|
| - const std::string& refresh_token) {
|
| + const std::string& refresh_token,
|
| + const std::vector<std::string>& scopes) {
|
| client_id_ = client_id;
|
| client_secret_ = client_secret;
|
| refresh_token_ = refresh_token;
|
| + scopes_ = scopes;
|
| StartGetAccessToken();
|
| }
|
|
|
| @@ -109,7 +120,8 @@
|
| fetcher_.reset(CreateFetcher(
|
| getter_,
|
| MakeGetAccessTokenUrl(),
|
| - MakeGetAccessTokenBody(client_id_, client_secret_, refresh_token_),
|
| + MakeGetAccessTokenBody(
|
| + client_id_, client_secret_, refresh_token_, scopes_),
|
| this));
|
| fetcher_->Start(); // OnURLFetchComplete will be called.
|
| }
|
| @@ -162,12 +174,28 @@
|
| std::string OAuth2AccessTokenFetcher::MakeGetAccessTokenBody(
|
| const std::string& client_id,
|
| const std::string& client_secret,
|
| - const std::string& refresh_token) {
|
| - return StringPrintf(
|
| - kGetAccessTokenBodyFormat,
|
| - net::EscapeUrlEncodedData(client_id, true).c_str(),
|
| - net::EscapeUrlEncodedData(client_secret, true).c_str(),
|
| - net::EscapeUrlEncodedData(refresh_token, true).c_str());
|
| + const std::string& refresh_token,
|
| + const std::vector<std::string>& scopes) {
|
| + std::string enc_client_id = net::EscapeUrlEncodedData(client_id, true);
|
| + std::string enc_client_secret =
|
| + net::EscapeUrlEncodedData(client_secret, true);
|
| + std::string enc_refresh_token =
|
| + net::EscapeUrlEncodedData(refresh_token, true);
|
| + if (scopes.empty()) {
|
| + return StringPrintf(
|
| + kGetAccessTokenBodyFormat,
|
| + enc_client_id.c_str(),
|
| + enc_client_secret.c_str(),
|
| + enc_refresh_token.c_str());
|
| + } else {
|
| + std::string scopes_string = JoinString(scopes, ',');
|
| + return StringPrintf(
|
| + kGetAccessTokenBodyWithScopeFormat,
|
| + enc_client_id.c_str(),
|
| + enc_client_secret.c_str(),
|
| + enc_refresh_token.c_str(),
|
| + net::EscapeUrlEncodedData(scopes_string, true).c_str());
|
| + }
|
| }
|
|
|
| // static
|
|
|