Chromium Code Reviews| Index: chrome/common/net/gaia/gaia_auth_fetcher.h |
| =================================================================== |
| --- chrome/common/net/gaia/gaia_auth_fetcher.h (revision 110361) |
| +++ chrome/common/net/gaia/gaia_auth_fetcher.h (working copy) |
| @@ -7,6 +7,7 @@ |
| #pragma once |
| #include <string> |
| +#include <vector> |
| #include "base/gtest_prod_util.h" |
| #include "base/memory/scoped_ptr.h" |
| @@ -29,6 +30,7 @@ |
| namespace net { |
| class URLRequestContextGetter; |
| class URLRequestStatus; |
| +typedef std::vector<std::string> ResponseCookies; |
| } |
| class GaiaAuthFetcher : public content::URLFetcherDelegate { |
| @@ -66,6 +68,12 @@ |
| const std::string& lsid, |
| const char* const service); |
| + // Start fetching OAuth login scoped token from the given ClientLogin token |
| + // for "lso" service. |
| + // Either OnOAuthLoginTokenSuccess or OnOAuthLoginTokenFailure method will be |
| + // called on the consumer with results. |
| + void StartOAuthLoginTokenFetch(const std::string& auth_token); |
| + |
| // Start a request to get a particular key from user info. |
| // GaiaAuthConsumer will be called back on the same thread when |
| // results come back. |
| @@ -109,6 +117,10 @@ |
| static const char kClientLoginCaptchaFormat[]; |
| // The format of the POST body for IssueAuthToken. |
| static const char kIssueAuthTokenFormat[]; |
| + // The format of the POST body to get OAuth2 auth code from auth token. |
| + static const char kClientLoginToOAuth2BodyFormat[]; |
| + // The format of the POST body to get OAuth2 token pair from auth code. |
| + static const char kOAuth2CodeToTokenPairBodyFormat[]; |
| // The format of the POST body for GetUserInfo. |
| static const char kGetUserInfoFormat[]; |
| // The format of the POST body for TokenAuth. |
| @@ -132,6 +144,16 @@ |
| static const char kCaptchaUrlParam[]; |
| static const char kCaptchaTokenParam[]; |
| + // Constants for request/response for OAtuh2 requests. |
|
Rick Campbell
2011/11/22 22:22:53
typo OAtuh2 --> OAuth2
Munjal (Google)
2011/11/22 22:29:24
Done.
|
| + static const char kAuthHeaderFormat[]; |
| + static const char kClientLoginToOAuth2CookiePartSecure[]; |
| + static const char kClientLoginToOAuth2CookiePartHttpOnly[]; |
| + static const char kClientLoginToOAuth2CookiePartCodePrefix[]; |
| + static const int kClientLoginToOAuth2CookiePartCodePrefixLength; |
| + static const char kOAuth2RefreshTokenKey[]; |
| + static const char kOAuth2AccessTokenKey[]; |
| + static const char kOAuth2ExpiresInKey[]; |
| + |
| // Process the results of a ClientLogin fetch. |
| void OnClientLoginFetched(const std::string& data, |
| const net::URLRequestStatus& status, |
| @@ -141,6 +163,15 @@ |
| const net::URLRequestStatus& status, |
| int response_code); |
| + void OnClientLoginToOAuth2Fetched(const std::string& data, |
| + const net::ResponseCookies& cookies, |
| + const net::URLRequestStatus& status, |
| + int response_code); |
| + |
| + void OnOAuth2TokenPairFetched(const std::string& data, |
| + const net::URLRequestStatus& status, |
| + int response_code); |
| + |
| void OnGetUserInfoFetched(const std::string& data, |
| const net::URLRequestStatus& status, |
| int response_code); |
| @@ -165,6 +196,20 @@ |
| std::string* captcha_url, |
| std::string* captcha_token); |
| + // Parse ClientLogin to OAuth2 response. |
| + static bool ParseClientLoginToOAuth2Response( |
| + const net::ResponseCookies& cookies, |
| + std::string* auth_code); |
| + |
| + // Parse OAuth2 token pairresponse. |
| + static bool ParseOAuth2TokenPairResponse(const std::string& data, |
| + std::string* refresh_token, |
| + std::string* access_token, |
| + int* expires_in_secs); |
| + |
| + static bool ParseClientLoginToOAuth2Cookie(const std::string& cookie, |
| + std::string* auth_code); |
| + |
| // Is this a special case Gaia error for TwoFactor auth? |
| static bool IsSecondFactorSuccess(const std::string& alleged_error); |
| @@ -182,6 +227,10 @@ |
| static std::string MakeIssueAuthTokenBody(const std::string& sid, |
| const std::string& lsid, |
| const char* const service); |
| + // Create body to get OAuth2 auth code. |
| + static std::string MakeGetAuthCodeBody(); |
| + // Given auth code, create body to get OAuth2 token pair. |
| + static std::string MakeGetTokenPairBody(const std::string& auth_code); |
| // Supply the lsid returned from ClientLogin in order to fetch |
| // user information. |
| static std::string MakeGetUserInfoBody(const std::string& lsid); |
| @@ -196,12 +245,17 @@ |
| const std::string& continue_url, |
| const std::string& source); |
| + static std::string MakeGetAuthCodeHeader(const std::string& auth_token); |
| + |
| + void StartOAuth2TokenPairFetch(const std::string& auth_code); |
| + |
| // Create a fetcher useable for making any Gaia request. |
| static content::URLFetcher* CreateGaiaFetcher( |
| net::URLRequestContextGetter* getter, |
| const std::string& body, |
| + const std::string& headers, |
| const GURL& gaia_gurl, |
| - bool send_cookies, |
| + bool use_cookies, |
|
Rick Campbell
2011/11/22 22:22:53
Nit -- this is called send_cookies in the source f
Munjal (Google)
2011/11/22 22:29:24
Done.
|
| content::URLFetcherDelegate* delegate); |
| // From a URLFetcher result, generate an appropriate error. |
| @@ -217,6 +271,8 @@ |
| std::string source_; |
| const GURL client_login_gurl_; |
| const GURL issue_auth_token_gurl_; |
| + const GURL client_login_to_oauth2_gurl_; |
| + const GURL oauth2_token_gurl_; |
| const GURL get_user_info_gurl_; |
| const GURL token_auth_gurl_; |
| const GURL merge_session_gurl_; |
| @@ -238,6 +294,9 @@ |
| FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); |
| FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); |
| FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); |
| + FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, |
| + ParseClientLoginToOAuth2Response); |
| + FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ParseOAuth2TokenPairResponse); |
| DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); |
| }; |