OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_ |
| 6 #define REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "google_apis/gaia/gaia_oauth_client.h" |
| 12 |
| 13 namespace remoting { |
| 14 namespace test { |
| 15 |
| 16 // Supplied by the client for each request to GAIA and returns valid tokens on |
| 17 // success or empty tokens on failure. |
| 18 typedef base::Callback<void( |
| 19 const std::string& access_token, |
| 20 const std::string& refresh_token)> AccessTokenCallback; |
| 21 |
| 22 // Retrieves an access token from either an authorization code or a refresh |
| 23 // token. Destroying the AccessTokenFetcher while a request is outstanding will |
| 24 // cancel the request. It is safe to delete the fetcher from within a completion |
| 25 // callback. Must be used from a thread running an IO message loop. |
| 26 // The public methods are virtual to allow for mocking and fakes. |
| 27 class AccessTokenFetcher : public gaia::GaiaOAuthClient::Delegate { |
| 28 public: |
| 29 AccessTokenFetcher(); |
| 30 ~AccessTokenFetcher() override; |
| 31 |
| 32 // Retrieve an access token from a one time use authorization code. |
| 33 virtual void GetAccessTokenFromAuthCode(const std::string& auth_code, |
| 34 const AccessTokenCallback& callback); |
| 35 |
| 36 // Retrieve an access token from a refresh token. |
| 37 virtual void GetAccessTokenFromRefreshToken( |
| 38 const std::string& refresh_token, |
| 39 const AccessTokenCallback& callback); |
| 40 |
| 41 private: |
| 42 // gaia::GaiaOAuthClient::Delegate Interface. |
| 43 void OnGetTokensResponse(const std::string& refresh_token, |
| 44 const std::string& access_token, |
| 45 int expires_in_seconds) override; |
| 46 void OnRefreshTokenResponse(const std::string& access_token, |
| 47 int expires_in_seconds) override; |
| 48 void OnGetUserEmailResponse(const std::string& user_email) override; |
| 49 void OnGetUserIdResponse(const std::string& user_id) override; |
| 50 void OnGetUserInfoResponse( |
| 51 scoped_ptr<base::DictionaryValue> user_info) override; |
| 52 void OnGetTokenInfoResponse( |
| 53 scoped_ptr<base::DictionaryValue> token_info) override; |
| 54 void OnOAuthError() override; |
| 55 void OnNetworkError(int response_code) override; |
| 56 |
| 57 // Updates |auth_client_| with a new GaiaOAuthClient instance. |
| 58 void CreateNewGaiaOAuthClientInstance(); |
| 59 |
| 60 // Validates the retrieved access token. |
| 61 void ValidateAccessToken(); |
| 62 |
| 63 // Caller-supplied callback used to return valid tokens on success or empty |
| 64 // tokens on failure. |
| 65 AccessTokenCallback access_token_callback_; |
| 66 |
| 67 // Retrieved based on the |refresh_token_|. |
| 68 std::string access_token_; |
| 69 |
| 70 // Supplied by the caller or retrieved from a caller-supplied auth token. |
| 71 std::string refresh_token_; |
| 72 |
| 73 // Holds the client id, secret, and redirect url used to make |
| 74 // the Gaia service request. |
| 75 gaia::OAuthClientInfo oauth_client_info_; |
| 76 |
| 77 // Used to make token requests to GAIA. |
| 78 scoped_ptr<gaia::GaiaOAuthClient> auth_client_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(AccessTokenFetcher); |
| 81 }; |
| 82 |
| 83 } // namespace test |
| 84 } // namespace remoting |
| 85 |
| 86 #endif // REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_ |
OLD | NEW |