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.
5 #ifndef REMOTING_HOST_TOKEN_VALIDATOR_BASE_H_
6 #define REMOTING_HOST_TOKEN_VALIDATOR_BASE_H_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "net/url_request/url_request.h"
11 #include "net/url_request/url_request_context_getter.h"
12 #include "remoting/protocol/token_validator.h"
16 class ClientCertStore
;
17 typedef std::vector
<scoped_refptr
<X509Certificate
> > CertificateList
;
22 struct ThirdPartyAuthConfig
{
23 inline bool is_empty() const {
24 return token_url
.is_empty() && token_validation_url
.is_empty();
27 inline bool is_valid() const {
28 return token_url
.is_valid() && token_validation_url
.is_valid();
32 GURL token_validation_url
;
33 std::string token_validation_cert_issuer
;
36 class TokenValidatorBase
37 : public net::URLRequest::Delegate
,
38 public protocol::TokenValidator
{
41 const ThirdPartyAuthConfig
& third_party_auth_config
,
42 const std::string
& token_scope
,
43 scoped_refptr
<net::URLRequestContextGetter
> request_context_getter
);
44 virtual ~TokenValidatorBase();
46 // TokenValidator interface.
47 virtual void ValidateThirdPartyToken(
48 const std::string
& token
,
49 const base::Callback
<void(
50 const std::string
& shared_secret
)>& on_token_validated
) OVERRIDE
;
52 virtual const GURL
& token_url() const OVERRIDE
;
53 virtual const std::string
& token_scope() const OVERRIDE
;
55 // URLRequest::Delegate interface.
56 virtual void OnResponseStarted(net::URLRequest
* source
) OVERRIDE
;
57 virtual void OnReadCompleted(net::URLRequest
* source
,
58 int bytes_read
) OVERRIDE
;
59 virtual void OnCertificateRequested(
60 net::URLRequest
* source
,
61 net::SSLCertRequestInfo
* cert_request_info
) OVERRIDE
;
64 void OnCertificatesSelected(net::CertificateList
* selected_certs
,
65 net::ClientCertStore
* unused
);
67 virtual void StartValidateRequest(const std::string
& token
) = 0;
68 virtual bool IsValidScope(const std::string
& token_scope
);
69 std::string
ProcessResponse();
71 // Constructor parameters.
72 ThirdPartyAuthConfig third_party_auth_config_
;
73 std::string token_scope_
;
74 scoped_refptr
<net::URLRequestContextGetter
> request_context_getter_
;
76 // URLRequest related fields.
77 scoped_ptr
<net::URLRequest
> request_
;
78 scoped_refptr
<net::IOBuffer
> buffer_
;
81 base::Callback
<void(const std::string
& shared_secret
)> on_token_validated_
;
83 base::WeakPtrFactory
<TokenValidatorBase
> weak_factory_
;
85 DISALLOW_COPY_AND_ASSIGN(TokenValidatorBase
);
88 } // namespace remoting
90 #endif // REMOTING_HOST_TOKEN_VALIDATOR_BASE_H