third_party_client_authenticator.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2013 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. #ifndef REMOTING_PROTOCOL_THIRD_PARTY_CLIENT_AUTHENTICATOR_H_
  5. #define REMOTING_PROTOCOL_THIRD_PARTY_CLIENT_AUTHENTICATOR_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "remoting/protocol/client_authentication_config.h"
  11. #include "remoting/protocol/third_party_authenticator_base.h"
  12. #include "remoting/protocol/token_validator.h"
  13. namespace remoting {
  14. namespace protocol {
  15. // Implements the client side of the third party authentication mechanism.
  16. // The client authenticator expects a |token_url| and |scope| in the first
  17. // message from the host, then calls the |TokenFetcher| asynchronously to
  18. // request a |token| and |shared_secret| from that url. If the server requires
  19. // interactive authentication, the |TokenFetcher| implementation will show the
  20. // appropriate UI. Once the |TokenFetcher| returns, the client sends the |token|
  21. // to the host, and uses the |shared_secret| to create an underlying
  22. // |V2Authenticator|, which is used to establish the encrypted connection.
  23. class ThirdPartyClientAuthenticator : public ThirdPartyAuthenticatorBase {
  24. public:
  25. // Creates a third-party client authenticator.
  26. // |create_base_authenticator_callback| is used to create the base
  27. // authenticator. |token_fetcher| is used to get the authentication token.
  28. ThirdPartyClientAuthenticator(
  29. const CreateBaseAuthenticatorCallback& create_base_authenticator_callback,
  30. const FetchThirdPartyTokenCallback& fetch_token_callback);
  31. ThirdPartyClientAuthenticator(const ThirdPartyClientAuthenticator&) = delete;
  32. ThirdPartyClientAuthenticator& operator=(
  33. const ThirdPartyClientAuthenticator&) = delete;
  34. ~ThirdPartyClientAuthenticator() override;
  35. protected:
  36. // ThirdPartyAuthenticator implementation.
  37. void ProcessTokenMessage(const jingle_xmpp::XmlElement* message,
  38. base::OnceClosure resume_callback) override;
  39. void AddTokenElements(jingle_xmpp::XmlElement* message) override;
  40. private:
  41. void OnThirdPartyTokenFetched(
  42. base::OnceClosure resume_callback,
  43. const std::string& third_party_token,
  44. const TokenValidator::ValidationResult& validation_result);
  45. CreateBaseAuthenticatorCallback create_base_authenticator_callback_;
  46. FetchThirdPartyTokenCallback fetch_token_callback_;
  47. std::string token_;
  48. base::WeakPtrFactory<ThirdPartyClientAuthenticator> weak_factory_{this};
  49. };
  50. } // namespace protocol
  51. } // namespace remoting
  52. #endif // REMOTING_PROTOCOL_THIRD_PARTY_CLIENT_AUTHENTICATOR_H_