blob: a10ab1a420be9a1dd180cfdeb9ec4965163d9684 [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
8#include "base/callback.h"
svaldez7872fd02015-11-19 21:10:549#include "base/memory/scoped_ptr.h"
[email protected]d95ee262014-02-26 06:30:3110#include "base/memory/weak_ptr.h"
11#include "net/url_request/url_request.h"
12#include "net/url_request/url_request_context_getter.h"
lukasza0d40d8a2015-03-03 18:36:2813#include "remoting/host/third_party_auth_config.h"
[email protected]d95ee262014-02-26 06:30:3114#include "remoting/protocol/token_validator.h"
15#include "url/gurl.h"
16
17namespace net {
18class ClientCertStore;
19typedef std::vector<scoped_refptr<X509Certificate> > CertificateList;
20}
21
22namespace remoting {
23
[email protected]d95ee262014-02-26 06:30:3124class 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);
dcheng562aba52014-10-21 12:30:1432 ~TokenValidatorBase() override;
[email protected]d95ee262014-02-26 06:30:3133
34 // TokenValidator interface.
dcheng562aba52014-10-21 12:30:1435 void ValidateThirdPartyToken(
[email protected]d95ee262014-02-26 06:30:3136 const std::string& token,
dcheng562aba52014-10-21 12:30:1437 const base::Callback<void(const std::string& shared_secret)>&
38 on_token_validated) override;
[email protected]d95ee262014-02-26 06:30:3139
dcheng562aba52014-10-21 12:30:1440 const GURL& token_url() const override;
41 const std::string& token_scope() const override;
[email protected]d95ee262014-02-26 06:30:3142
43 // URLRequest::Delegate interface.
dcheng562aba52014-10-21 12:30:1444 void OnResponseStarted(net::URLRequest* source) override;
45 void OnReadCompleted(net::URLRequest* source, int bytes_read) override;
46 void OnCertificateRequested(
[email protected]d95ee262014-02-26 06:30:3147 net::URLRequest* source,
mostynb11d989c2014-10-08 16:58:0948 net::SSLCertRequestInfo* cert_request_info) override;
[email protected]d95ee262014-02-26 06:30:3149
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