OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/net/gaia/gaia_oauth_client.h" | 5 #include "chrome/common/net/gaia/gaia_oauth_client.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/common/net/http_return.h" | 10 #include "chrome/common/net/http_return.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 GaiaOAuthClient::Delegate* delegate_; | 69 GaiaOAuthClient::Delegate* delegate_; |
70 scoped_ptr<URLFetcher> request_; | 70 scoped_ptr<URLFetcher> request_; |
71 }; | 71 }; |
72 | 72 |
73 void GaiaOAuthClient::Core::GetTokensFromAuthCode( | 73 void GaiaOAuthClient::Core::GetTokensFromAuthCode( |
74 const OAuthClientInfo& oauth_client_info, | 74 const OAuthClientInfo& oauth_client_info, |
75 const std::string& auth_code, | 75 const std::string& auth_code, |
76 int max_retries, | 76 int max_retries, |
77 GaiaOAuthClient::Delegate* delegate) { | 77 GaiaOAuthClient::Delegate* delegate) { |
78 std::string post_body = | 78 std::string post_body = |
79 "code=" + EscapeUrlEncodedData(auth_code) + | 79 "code=" + EscapeUrlEncodedData(auth_code, true) + |
80 "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id) + | 80 "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id, true) + |
81 "&client_secret=" + | 81 "&client_secret=" + |
82 EscapeUrlEncodedData(oauth_client_info.client_secret) + | 82 EscapeUrlEncodedData(oauth_client_info.client_secret, true) + |
83 "&redirect_uri=oob&grant_type=authorization_code"; | 83 "&redirect_uri=oob&grant_type=authorization_code"; |
84 MakeGaiaRequest(post_body, max_retries, delegate); | 84 MakeGaiaRequest(post_body, max_retries, delegate); |
85 } | 85 } |
86 | 86 |
87 void GaiaOAuthClient::Core::RefreshToken( | 87 void GaiaOAuthClient::Core::RefreshToken( |
88 const OAuthClientInfo& oauth_client_info, | 88 const OAuthClientInfo& oauth_client_info, |
89 const std::string& refresh_token, | 89 const std::string& refresh_token, |
90 int max_retries, | 90 int max_retries, |
91 GaiaOAuthClient::Delegate* delegate) { | 91 GaiaOAuthClient::Delegate* delegate) { |
92 std::string post_body = | 92 std::string post_body = |
93 "refresh_token=" + EscapeUrlEncodedData(refresh_token) + | 93 "refresh_token=" + EscapeUrlEncodedData(refresh_token, true) + |
94 "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id) + | 94 "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id, true) + |
95 "&client_secret=" + | 95 "&client_secret=" + |
96 EscapeUrlEncodedData(oauth_client_info.client_secret) + | 96 EscapeUrlEncodedData(oauth_client_info.client_secret, true) + |
97 "&grant_type=refresh_token"; | 97 "&grant_type=refresh_token"; |
98 MakeGaiaRequest(post_body, max_retries, delegate); | 98 MakeGaiaRequest(post_body, max_retries, delegate); |
99 } | 99 } |
100 | 100 |
101 void GaiaOAuthClient::Core::MakeGaiaRequest( | 101 void GaiaOAuthClient::Core::MakeGaiaRequest( |
102 std::string post_body, | 102 std::string post_body, |
103 int max_retries, | 103 int max_retries, |
104 GaiaOAuthClient::Delegate* delegate) { | 104 GaiaOAuthClient::Delegate* delegate) { |
105 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; | 105 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; |
106 delegate_ = delegate; | 106 delegate_ = delegate; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 const std::string& refresh_token, | 208 const std::string& refresh_token, |
209 int max_retries, | 209 int max_retries, |
210 Delegate* delegate) { | 210 Delegate* delegate) { |
211 return core_->RefreshToken(oauth_client_info, | 211 return core_->RefreshToken(oauth_client_info, |
212 refresh_token, | 212 refresh_token, |
213 max_retries, | 213 max_retries, |
214 delegate); | 214 delegate); |
215 } | 215 } |
216 | 216 |
217 } // namespace gaia | 217 } // namespace gaia |
OLD | NEW |