[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 1 | // Copyright 2014 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_HOST_TOKEN_VALIDATOR_BASE_H_ |
| 6 | #define REMOTING_HOST_TOKEN_VALIDATOR_BASE_H_ |
| 7 | |
| 8 | #include "base/callback.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
| 11 | #include "net/url_request/url_request.h" |
| 12 | #include "net/url_request/url_request_context_getter.h" |
lukasza | 0d40d8a | 2015-03-03 18:36:28 | [diff] [blame] | 13 | #include "remoting/host/third_party_auth_config.h" |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 14 | #include "remoting/protocol/token_validator.h" |
| 15 | #include "url/gurl.h" |
| 16 | |
| 17 | namespace net { |
| 18 | class ClientCertStore; |
| 19 | typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
| 20 | } |
| 21 | |
| 22 | namespace remoting { |
| 23 | |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 24 | class TokenValidatorBase |
| 25 | : public net::URLRequest::Delegate, |
| 26 | public protocol::TokenValidator { |
| 27 | public: |
| 28 | TokenValidatorBase( |
| 29 | const ThirdPartyAuthConfig& third_party_auth_config, |
| 30 | const std::string& token_scope, |
| 31 | scoped_refptr<net::URLRequestContextGetter> request_context_getter); |
dcheng | 562aba5 | 2014-10-21 12:30:14 | [diff] [blame] | 32 | ~TokenValidatorBase() override; |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 33 | |
| 34 | // TokenValidator interface. |
dcheng | 562aba5 | 2014-10-21 12:30:14 | [diff] [blame] | 35 | void ValidateThirdPartyToken( |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 36 | const std::string& token, |
dcheng | 562aba5 | 2014-10-21 12:30:14 | [diff] [blame] | 37 | const base::Callback<void(const std::string& shared_secret)>& |
| 38 | on_token_validated) override; |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 39 | |
dcheng | 562aba5 | 2014-10-21 12:30:14 | [diff] [blame] | 40 | const GURL& token_url() const override; |
| 41 | const std::string& token_scope() const override; |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 42 | |
| 43 | // URLRequest::Delegate interface. |
dcheng | 562aba5 | 2014-10-21 12:30:14 | [diff] [blame] | 44 | void OnResponseStarted(net::URLRequest* source) override; |
| 45 | void OnReadCompleted(net::URLRequest* source, int bytes_read) override; |
| 46 | void OnCertificateRequested( |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 47 | net::URLRequest* source, |
mostynb | 11d989c | 2014-10-08 16:58:09 | [diff] [blame] | 48 | net::SSLCertRequestInfo* cert_request_info) override; |
[email protected] | d95ee26 | 2014-02-26 06:30:31 | [diff] [blame] | 49 | |
| 50 | protected: |
| 51 | void OnCertificatesSelected(net::CertificateList* selected_certs, |
| 52 | net::ClientCertStore* unused); |
| 53 | |
| 54 | virtual void StartValidateRequest(const std::string& token) = 0; |
| 55 | virtual bool IsValidScope(const std::string& token_scope); |
| 56 | std::string ProcessResponse(); |
| 57 | |
| 58 | // Constructor parameters. |
| 59 | ThirdPartyAuthConfig third_party_auth_config_; |
| 60 | std::string token_scope_; |
| 61 | scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 62 | |
| 63 | // URLRequest related fields. |
| 64 | scoped_ptr<net::URLRequest> request_; |
| 65 | scoped_refptr<net::IOBuffer> buffer_; |
| 66 | std::string data_; |
| 67 | |
| 68 | base::Callback<void(const std::string& shared_secret)> on_token_validated_; |
| 69 | |
| 70 | base::WeakPtrFactory<TokenValidatorBase> weak_factory_; |
| 71 | |
| 72 | DISALLOW_COPY_AND_ASSIGN(TokenValidatorBase); |
| 73 | }; |
| 74 | |
| 75 | } // namespace remoting |
| 76 | |
| 77 | #endif // REMOTING_HOST_TOKEN_VALIDATOR_BASE_H |