Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4632)

Unified Diff: chrome/common/net/gaia/authentication_fetcher_oauth.h

Issue 6894027: Initial refactoring complete Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed some tests that were broken by previous refactoring Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/net/gaia/authentication_fetcher_oauth.h
diff --git a/chrome/common/net/gaia/authentication_fetcher_oauth.h b/chrome/common/net/gaia/authentication_fetcher_oauth.h
new file mode 100644
index 0000000000000000000000000000000000000000..963d1bb2f9ba6fd7a23637f863b4a80250bc24ba
--- /dev/null
+++ b/chrome/common/net/gaia/authentication_fetcher_oauth.h
@@ -0,0 +1,202 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_NET_GAIA_AUTHENTICATION_FETCHER_OAUTH_H_
+#define CHROME_COMMON_NET_GAIA_AUTHENTICATION_FETCHER_OAUTH_H_
+#pragma once
+
+#include <string>
+
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/common/net/gaia/authentication_fetcher.h"
+#include "chrome/common/net/gaia/authentication_consumer_oauth.h"
+#include "chrome/common/net/url_fetcher.h"
+#include "googleurl/src/gurl.h"
+
+// Authenticate a user against the Google Accounts Authentication API with
+// various capabilities and return results to a AuthenticationConsumerOAuth.
+//
+// In the future, we will also issue auth tokens from this class.
+// This class should be used on a single thread, but it can be whichever thread
+// that you like.
+//
+// This class can handle one request at a time. To parallelize requests,
+// create multiple AuthenticationFetcherOAuth's.
+
+class AuthenticationFetcherOAuthTest;
+
+class AuthenticationFetcherOAuth : public AuthenticationFetcher {
+ public:
+ // The URLs for different calls in the Google Accounts programmatic login API.
+ static const char kAuthenticationUrl[];
+ static const char kIssueAuthTokenUrl[];
+ static const char kGetUserInfoUrl[];
+
+ // Magic string indicating that, while a second factor is still
+ // needed to complete authentication, the user provided the right password.
+ static const char kSecondFactor[];
+
+ // This will later be hidden behind an auth service which caches
+ // tokens.
+ AuthenticationFetcherOAuth(AuthenticationConsumerOAuth* consumer,
+ const std::string& source,
+ net::URLRequestContextGetter* getter);
+ virtual ~AuthenticationFetcherOAuth();
+
+ // AuthenticationConsumerOAuth will be called on the original thread
+ // after results come back. This class is thread agnostic.
+ // You can't make more than request at a time.
+ virtual void StartAuthentication(const std::string& username,
+ const std::string& password,
+ const char* const service,
+ const std::string& login_token,
+ const std::string& login_captcha,
+ HostedAccountsSetting allow_hosted_accounts);
+
+ // AuthenticationConsumerOAuth will be called on the original thread
+ // after results come back. This class is thread agnostic.
+ // You can't make more than one request at a time.
+ virtual void StartIssueAuthToken(
+ const AuthenticationConsumer::AuthenticationResult& credentials,
+ const char* const service);
+
+ // Start a request to get a particular key from user info.
+ // AuthenticationConsumerOAuth will be called back on the same thread when
+ // results come back.
+ // You can't make more than one request at a time.
+ virtual void StartGetUserInfo(const std::string& lsid,
+ const std::string& info_key);
+
+ // Implementation of URLFetcher::Delegate
+ virtual void OnURLFetchComplete(const URLFetcher* source,
+ const GURL& url,
+ const net::URLRequestStatus& status,
+ int response_code,
+ const ResponseCookies& cookies,
+ const std::string& data);
+
+ private:
+ // Authentication body constants that don't change
+ static const char kCookiePersistence[];
+ static const char kAccountTypeHostedOrGoogle[];
+ static const char kAccountTypeGoogle[];
+
+ // The format of the POST body for Authentication.
+ static const char kAuthenticationFormat[];
+ // The format of said POST body when CAPTCHA token & answer are specified.
+ static const char kAuthenticationCaptchaFormat[];
+ // The format of the POST body for IssueAuthToken.
+ static const char kIssueAuthTokenFormat[];
+ // The format of the POSt body for GetUserInfo.
+ static const char kGetUserInfoFormat[];
+
+ // Constants for parsing Authentication errors.
+ static const char kAccountDeletedError[];
+ static const char kAccountDisabledError[];
+ static const char kBadAuthenticationError[];
+ static const char kCaptchaError[];
+ static const char kServiceUnavailableError[];
+ static const char kErrorParam[];
+ static const char kErrorUrlParam[];
+ static const char kCaptchaUrlParam[];
+ static const char kCaptchaTokenParam[];
+ static const char kCaptchaUrlPrefix[];
+
+ // Process the results of a Authentication fetch.
+ void OnAuthenticationFetched(const std::string& data,
+ const net::URLRequestStatus& status,
+ int response_code);
+
+ void OnIssueAuthTokenFetched(const std::string& data,
+ const net::URLRequestStatus& status,
+ int response_code);
+
+ void OnGetUserInfoFetched(const std::string& data,
+ const net::URLRequestStatus& status,
+ int response_code);
+
+ // Tokenize the results of a Authentication fetch.
+ static void ParseAuthenticationResponse(const std::string& data,
+ std::string* sid,
+ std::string* lsid,
+ std::string* token);
+
+ static void ParseAuthenticationFailure(const std::string& data,
+ std::string* error,
+ std::string* error_url,
+ std::string* captcha_url,
+ std::string* captcha_token);
+
+ // From a URLFetcher result, generate an appropriate error.
+ // From the API documentation, both IssueAuthToken and Authentication have
+ // the same error returns.
+ static GoogleServiceAuthError GenerateAuthError(
+ const std::string& data,
+ const net::URLRequestStatus& status);
+
+ // Is this a special case Gaia error for TwoFactor auth?
+ static bool IsSecondFactorSuccess(const std::string& alleged_error);
+
+ // Given parameters, create a Authentication request body.
+ static std::string MakeAuthenticationBody(
+ const std::string& username,
+ const std::string& password,
+ const std::string& source,
+ const char* const service,
+ const std::string& login_token,
+ const std::string& login_captcha,
+ HostedAccountsSetting allow_hosted_accounts);
+ // Supply the sid / lsid returned from Authentication in order to
+ // request a long lived auth token for a service.
+
+ static std::string MakeIssueAuthTokenBody(
+ const AuthenticationConsumer::AuthenticationResult& credentials,
+ const char* const service);
+ // Supply the lsid returned from Authentication in order to fetch
+ // user information.
+ static std::string MakeGetUserInfoBody(const std::string& lsid);
+
+ // Create a fetcher useable for making any Gaia request.
+ static URLFetcher* CreateAuthenticationFetcherOAuth(
+ net::URLRequestContextGetter* getter,
+ const std::string& body,
+ const GURL& gaia_gurl_,
+ URLFetcher::Delegate* delegate);
+
+ // These fields are common to AuthenticationFetcherOAuth, same every request
+ // AuthenticationConsumer* const consumer_;
+ // net::URLRequestContextGetter* const getter_;
+ // std::string source_;
+ const GURL oauth_gurl_;
+ const GURL issue_auth_token_gurl_;
+ const GURL get_user_info_gurl_;
+
+ // While a fetch is going on:
+ scoped_ptr<URLFetcher> fetcher_;
+ std::string request_body_;
+ std::string requested_service_; // Currently tracked for IssueAuthToken only
+ std::string requested_info_key_; // Currently tracked for GetUserInfo only
+
+ friend class AuthenticationFetcherOAuthTest;
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest, CaptchaParse);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest, AccountDeletedError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest,
+ AccountDisabledError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest,
+ BadAuthenticationError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest,
+ IncomprehensibleError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest,
+ ServiceUnavailableError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest,
+ CheckNormalErrorCode);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest,
+ CheckTwoFactorResponse);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherOAuthTest, LoginNetFailure);
+
+ DISALLOW_COPY_AND_ASSIGN(AuthenticationFetcherOAuth);
+};
+
+#endif // CHROME_COMMON_NET_GAIA_AUTHENTICATION_FETCHER_OAUTH_H_
« no previous file with comments | « chrome/common/net/gaia/authentication_fetcher.cc ('k') | chrome/common/net/gaia/authentication_fetcher_oauth.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698