OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_AUTH_H_ |
| 6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_AUTH_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/values.h" |
| 12 #include "chrome/common/net/gaia/gaia_oauth_client.h" |
| 13 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
| 14 #include "googleurl/src/gurl.h" |
| 15 |
| 16 // CloudPrintAuth is a class to handle login, token refresh, and other |
| 17 // authentication tasks for Cloud Print. |
| 18 // CloudPrintAuth will create new robot account for this proxy if needed. |
| 19 // CloudPrintAuth will obtain new OAuth token. |
| 20 // CloudPrintAuth will schedule periodic OAuth token refresh |
| 21 // It is running in the same thread as CloudPrintProxyBackend::Core. |
| 22 class CloudPrintAuth |
| 23 : public base::RefCountedThreadSafe<CloudPrintAuth>, |
| 24 public CloudPrintURLFetcherDelegate, |
| 25 public gaia::GaiaOAuthClient::Delegate { |
| 26 public: |
| 27 class Client { |
| 28 public: |
| 29 virtual void OnAuthenticationComplete( |
| 30 const std::string& access_token, |
| 31 const std::string& robot_oauth_refresh_token, |
| 32 const std::string& robot_email, |
| 33 const std::string& user_email) = 0; |
| 34 virtual void OnInvalidCredentials() = 0; |
| 35 protected: |
| 36 virtual ~Client() {} |
| 37 }; |
| 38 |
| 39 CloudPrintAuth(Client* client, |
| 40 const GURL& cloud_print_server_url, |
| 41 const base::DictionaryValue* print_sys_settings, |
| 42 const gaia::OAuthClientInfo& oauth_client_info, |
| 43 const std::string& proxy_id); |
| 44 virtual ~CloudPrintAuth(); |
| 45 |
| 46 // Note: |
| 47 // |
| 48 // The Authenticate* methods are the various entry points from |
| 49 // CloudPrintProxyBackend::Core. It calls us on a dedicated thread to |
| 50 // actually perform synchronous (and potentially blocking) operations. |
| 51 // |
| 52 // When we are passed in an LSID we authenticate using that |
| 53 // and retrieve new auth tokens. |
| 54 void AuthenticateWithLsid(const std::string& lsid, |
| 55 const std::string& last_robot_refresh_token, |
| 56 const std::string& last_robot_email, |
| 57 const std::string& last_user_email); |
| 58 |
| 59 void AuthenticateWithToken(const std::string cloud_print_token); |
| 60 void AuthenticateWithRobotToken(const std::string& robot_oauth_refresh_token, |
| 61 const std::string& robot_email); |
| 62 void AuthenticateWithRobotAuthCode(const std::string& robot_oauth_auth_code, |
| 63 const std::string& robot_email); |
| 64 |
| 65 void RefreshAccessToken(); |
| 66 |
| 67 // gaia::GaiaOAuthClient::Delegate implementation. |
| 68 virtual void OnGetTokensResponse(const std::string& refresh_token, |
| 69 const std::string& access_token, |
| 70 int expires_in_seconds); |
| 71 virtual void OnRefreshTokenResponse(const std::string& access_token, |
| 72 int expires_in_seconds); |
| 73 virtual void OnOAuthError(); |
| 74 virtual void OnNetworkError(int response_code); |
| 75 |
| 76 // CloudPrintURLFetcher::Delegate implementation. |
| 77 virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( |
| 78 const content::URLFetcher* source, |
| 79 const GURL& url, |
| 80 base::DictionaryValue* json_data, |
| 81 bool succeeded); |
| 82 virtual CloudPrintURLFetcher::ResponseAction OnRequestAuthError(); |
| 83 virtual std::string GetAuthHeader(); |
| 84 |
| 85 private: |
| 86 Client* client_; |
| 87 gaia::OAuthClientInfo oauth_client_info_; |
| 88 scoped_ptr<gaia::GaiaOAuthClient> oauth_client_; |
| 89 scoped_ptr<DictionaryValue> print_system_settings_; |
| 90 |
| 91 // The CloudPrintURLFetcher instance for the current request. |
| 92 scoped_refptr<CloudPrintURLFetcher> request_; |
| 93 |
| 94 GURL cloud_print_server_url_; |
| 95 // Proxy id, need to send to the cloud print server to find and update |
| 96 // necessary printers during the migration process. |
| 97 const std::string& proxy_id_; |
| 98 // The OAuth2 refresh token for the robot. |
| 99 std::string refresh_token_; |
| 100 // The email address of the user. This is only used during initial |
| 101 // authentication with an LSID. This is only used for storing in prefs for |
| 102 // display purposes. |
| 103 std::string user_email_; |
| 104 // The email address of the robot account. |
| 105 std::string robot_email_; |
| 106 // client login token used to authenticate request to cloud print server to |
| 107 // get the robot account. |
| 108 std::string client_login_token_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(CloudPrintAuth); |
| 111 }; |
| 112 |
| 113 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_AUTH_H_ |
| 114 |
OLD | NEW |