xref: /aosp_15_r20/external/cronet/net/http/http_auth_handler_basic.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 The Chromium Authors
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 NET_HTTP_HTTP_AUTH_HANDLER_BASIC_H_
6 #define NET_HTTP_HTTP_AUTH_HANDLER_BASIC_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "net/base/completion_once_callback.h"
12 #include "net/base/net_export.h"
13 #include "net/http/http_auth_handler.h"
14 #include "net/http/http_auth_handler_factory.h"
15 
16 namespace net {
17 
18 // Code for handling http basic authentication.
19 class NET_EXPORT_PRIVATE HttpAuthHandlerBasic : public HttpAuthHandler {
20  public:
21   class NET_EXPORT_PRIVATE Factory : public HttpAuthHandlerFactory {
22    public:
23     Factory();
24     ~Factory() override;
25 
26     int CreateAuthHandler(
27         HttpAuthChallengeTokenizer* challenge,
28         HttpAuth::Target target,
29         const SSLInfo& ssl_info,
30         const NetworkAnonymizationKey& network_anonymization_key,
31         const url::SchemeHostPort& scheme_host_port,
32         CreateReason reason,
33         int digest_nonce_count,
34         const NetLogWithSource& net_log,
35         HostResolver* host_resolver,
36         std::unique_ptr<HttpAuthHandler>* handler) override;
37   };
38 
39   ~HttpAuthHandlerBasic() override = default;
40 
41  private:
42   // HttpAuthHandler
43   bool Init(HttpAuthChallengeTokenizer* challenge,
44             const SSLInfo& ssl_info,
45             const NetworkAnonymizationKey& network_anonymization_key) override;
46   int GenerateAuthTokenImpl(const AuthCredentials* credentials,
47                             const HttpRequestInfo* request,
48                             CompletionOnceCallback callback,
49                             std::string* auth_token) override;
50   HttpAuth::AuthorizationResult HandleAnotherChallengeImpl(
51       HttpAuthChallengeTokenizer* challenge) override;
52 
53   bool ParseChallenge(HttpAuthChallengeTokenizer* challenge);
54 };
55 
56 }  // namespace net
57 
58 #endif  // NET_HTTP_HTTP_AUTH_HANDLER_BASIC_H_
59