Avi Drissman | d6cdf9b | 2022-09-15 19:52:53 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 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_PROTOCOL_THIRD_PARTY_CLIENT_AUTHENTICATOR_H_ |
| 6 | #define REMOTING_PROTOCOL_THIRD_PARTY_CLIENT_AUTHENTICATOR_H_ |
| 7 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Avi Drissman | 135261e | 2023-01-11 22:43:15 | [diff] [blame^] | 11 | #include "base/functional/callback.h" |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
sergeyu | 64adc27 | 2016-03-12 09:12:43 | [diff] [blame] | 13 | #include "remoting/protocol/client_authentication_config.h" |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 14 | #include "remoting/protocol/third_party_authenticator_base.h" |
Joe Downing | 2f836a8 | 2021-07-24 06:03:54 | [diff] [blame] | 15 | #include "remoting/protocol/token_validator.h" |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 16 | |
Joe Downing | 39d710e | 2022-08-25 20:11:45 | [diff] [blame] | 17 | namespace remoting::protocol { |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 18 | |
| 19 | // Implements the client side of the third party authentication mechanism. |
| 20 | // The client authenticator expects a |token_url| and |scope| in the first |
| 21 | // message from the host, then calls the |TokenFetcher| asynchronously to |
| 22 | // request a |token| and |shared_secret| from that url. If the server requires |
| 23 | // interactive authentication, the |TokenFetcher| implementation will show the |
| 24 | // appropriate UI. Once the |TokenFetcher| returns, the client sends the |token| |
| 25 | // to the host, and uses the |shared_secret| to create an underlying |
| 26 | // |V2Authenticator|, which is used to establish the encrypted connection. |
| 27 | class ThirdPartyClientAuthenticator : public ThirdPartyAuthenticatorBase { |
| 28 | public: |
sergeyu | 12e320a | 2016-03-08 18:10:28 | [diff] [blame] | 29 | // Creates a third-party client authenticator. |
| 30 | // |create_base_authenticator_callback| is used to create the base |
| 31 | // authenticator. |token_fetcher| is used to get the authentication token. |
| 32 | ThirdPartyClientAuthenticator( |
| 33 | const CreateBaseAuthenticatorCallback& create_base_authenticator_callback, |
sergeyu | 1acf67ba | 2016-03-10 02:59:14 | [diff] [blame] | 34 | const FetchThirdPartyTokenCallback& fetch_token_callback); |
Peter Boström | e9178e4 | 2021-09-22 18:11:49 | [diff] [blame] | 35 | |
| 36 | ThirdPartyClientAuthenticator(const ThirdPartyClientAuthenticator&) = delete; |
| 37 | ThirdPartyClientAuthenticator& operator=( |
| 38 | const ThirdPartyClientAuthenticator&) = delete; |
| 39 | |
dcheng | 562aba5 | 2014-10-21 12:30:14 | [diff] [blame] | 40 | ~ThirdPartyClientAuthenticator() override; |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 41 | |
| 42 | protected: |
| 43 | // ThirdPartyAuthenticator implementation. |
Mirko Bonadei | 80d1cea | 2019-01-18 22:22:17 | [diff] [blame] | 44 | void ProcessTokenMessage(const jingle_xmpp::XmlElement* message, |
Evan Stade | ce9372b | 2020-03-12 01:28:16 | [diff] [blame] | 45 | base::OnceClosure resume_callback) override; |
Mirko Bonadei | 80d1cea | 2019-01-18 22:22:17 | [diff] [blame] | 46 | void AddTokenElements(jingle_xmpp::XmlElement* message) override; |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 47 | |
| 48 | private: |
Joe Downing | 2f836a8 | 2021-07-24 06:03:54 | [diff] [blame] | 49 | void OnThirdPartyTokenFetched( |
| 50 | base::OnceClosure resume_callback, |
| 51 | const std::string& third_party_token, |
| 52 | const TokenValidator::ValidationResult& validation_result); |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 53 | |
sergeyu | 12e320a | 2016-03-08 18:10:28 | [diff] [blame] | 54 | CreateBaseAuthenticatorCallback create_base_authenticator_callback_; |
sergeyu | 1acf67ba | 2016-03-10 02:59:14 | [diff] [blame] | 55 | FetchThirdPartyTokenCallback fetch_token_callback_; |
sergeyu | 12e320a | 2016-03-08 18:10:28 | [diff] [blame] | 56 | std::string token_; |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 57 | |
Jeremy Roman | 7c5cfabd | 2019-08-12 15:45:27 | [diff] [blame] | 58 | base::WeakPtrFactory<ThirdPartyClientAuthenticator> weak_factory_{this}; |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 59 | }; |
| 60 | |
Joe Downing | 39d710e | 2022-08-25 20:11:45 | [diff] [blame] | 61 | } // namespace remoting::protocol |
[email protected] | 9a6361d0 | 2013-03-23 16:27:52 | [diff] [blame] | 62 | |
| 63 | #endif // REMOTING_PROTOCOL_THIRD_PARTY_CLIENT_AUTHENTICATOR_H_ |