blob: b79e33f05ec082bfdeacce6e706fea424a27dd25 [file] [log] [blame]
[email protected]d95ee262014-02-26 06:30:311// 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
dcheng0765c492016-04-06 22:41:538#include <memory>
9
[email protected]d95ee262014-02-26 06:30:3110#include "base/callback.h"
avic5960f32015-12-22 22:49:4811#include "base/macros.h"
[email protected]d95ee262014-02-26 06:30:3112#include "base/memory/weak_ptr.h"
mattm436ccfe2017-06-19 20:24:0813#include "net/ssl/client_cert_identity.h"
[email protected]d95ee262014-02-26 06:30:3114#include "net/url_request/url_request.h"
15#include "net/url_request/url_request_context_getter.h"
lukasza0d40d8a2015-03-03 18:36:2816#include "remoting/host/third_party_auth_config.h"
[email protected]d95ee262014-02-26 06:30:3117#include "remoting/protocol/token_validator.h"
18#include "url/gurl.h"
19
20namespace net {
21class ClientCertStore;
[email protected]d95ee262014-02-26 06:30:3122}
23
24namespace remoting {
25
[email protected]d95ee262014-02-26 06:30:3126class TokenValidatorBase
27 : public net::URLRequest::Delegate,
28 public protocol::TokenValidator {
29 public:
30 TokenValidatorBase(
31 const ThirdPartyAuthConfig& third_party_auth_config,
32 const std::string& token_scope,
33 scoped_refptr<net::URLRequestContextGetter> request_context_getter);
dcheng562aba52014-10-21 12:30:1434 ~TokenValidatorBase() override;
[email protected]d95ee262014-02-26 06:30:3135
36 // TokenValidator interface.
dcheng562aba52014-10-21 12:30:1437 void ValidateThirdPartyToken(
[email protected]d95ee262014-02-26 06:30:3138 const std::string& token,
dcheng562aba52014-10-21 12:30:1439 const base::Callback<void(const std::string& shared_secret)>&
40 on_token_validated) override;
[email protected]d95ee262014-02-26 06:30:3141
dcheng562aba52014-10-21 12:30:1442 const GURL& token_url() const override;
43 const std::string& token_scope() const override;
[email protected]d95ee262014-02-26 06:30:3144
45 // URLRequest::Delegate interface.
maksim.sisovc023fa22016-09-22 04:16:3246 void OnResponseStarted(net::URLRequest* source, int net_result) override;
47 void OnReadCompleted(net::URLRequest* source, int net_result) override;
lambroslambrouf43816ad2015-12-16 03:50:1448 void OnReceivedRedirect(net::URLRequest* request,
49 const net::RedirectInfo& redirect_info,
50 bool* defer_redirect) override;
dcheng562aba52014-10-21 12:30:1451 void OnCertificateRequested(
[email protected]d95ee262014-02-26 06:30:3152 net::URLRequest* source,
mostynb11d989c2014-10-08 16:58:0953 net::SSLCertRequestInfo* cert_request_info) override;
[email protected]d95ee262014-02-26 06:30:3154
55 protected:
mattm7ed243f2017-04-28 05:28:5856 void OnCertificatesSelected(net::ClientCertStore* unused,
mattm436ccfe2017-06-19 20:24:0857 net::ClientCertIdentityList selected_certs);
[email protected]d95ee262014-02-26 06:30:3158
59 virtual void StartValidateRequest(const std::string& token) = 0;
mattm436ccfe2017-06-19 20:24:0860 virtual void ContinueWithCertificate(
61 scoped_refptr<net::X509Certificate> client_cert,
62 scoped_refptr<net::SSLPrivateKey> client_private_key);
[email protected]d95ee262014-02-26 06:30:3163 virtual bool IsValidScope(const std::string& token_scope);
maksim.sisovc023fa22016-09-22 04:16:3264 std::string ProcessResponse(int net_result);
[email protected]d95ee262014-02-26 06:30:3165
66 // Constructor parameters.
67 ThirdPartyAuthConfig third_party_auth_config_;
68 std::string token_scope_;
69 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
70
71 // URLRequest related fields.
dcheng0765c492016-04-06 22:41:5372 std::unique_ptr<net::URLRequest> request_;
[email protected]d95ee262014-02-26 06:30:3173 scoped_refptr<net::IOBuffer> buffer_;
74 std::string data_;
75
lambroslambrouf43816ad2015-12-16 03:50:1476 // This is set by OnReceivedRedirect() if the token validation request is
77 // being re-submitted as a POST request. This can happen if the authentication
78 // cookie has not yet been set, and a login handler redirection causes the
79 // POST request to be turned into a GET operation, losing the POST data. In
80 // this case, an immediate retry (with the same cookie jar) is expected to
81 // succeeed.
82 bool retrying_request_ = false;
83
84 // Stores the most recently requested token, in case the validation request
85 // needs to be retried.
86 std::string token_;
87
[email protected]d95ee262014-02-26 06:30:3188 base::Callback<void(const std::string& shared_secret)> on_token_validated_;
89
Jeremy Roman7c5cfabd2019-08-12 15:45:2790 base::WeakPtrFactory<TokenValidatorBase> weak_factory_{this};
[email protected]d95ee262014-02-26 06:30:3191
92 DISALLOW_COPY_AND_ASSIGN(TokenValidatorBase);
93};
94
95} // namespace remoting
96
97#endif // REMOTING_HOST_TOKEN_VALIDATOR_BASE_H