blob: 6919abd21437cc9651323f03ee8734e6571d623e [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2018 The Chromium Authors
Clark DuVall502f66392019-01-23 16:55:172// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Asanka Herath57f2d942019-11-16 04:21:495#ifndef NET_HTTP_HTTP_AUTH_MECHANISM_H_
6#define NET_HTTP_HTTP_AUTH_MECHANISM_H_
Clark DuVall502f66392019-01-23 16:55:177
Asanka Herath3e017f9d2019-11-18 20:53:188#include <memory>
9
Avi Drissman41c4a412023-01-11 22:45:3710#include "base/functional/callback_forward.h"
Clark DuVall502f66392019-01-23 16:55:1711#include "net/base/completion_once_callback.h"
12#include "net/base/net_export.h"
13#include "net/http/http_auth.h"
14
15namespace net {
16
17class AuthCredentials;
18class HttpAuthChallengeTokenizer;
Asanka Herath3e017f9d2019-11-18 20:53:1819class HttpAuthPreferences;
Asanka Herath310ef922019-07-23 19:56:3920class NetLogWithSource;
Clark DuVall502f66392019-01-23 16:55:1721
Asanka Herath57f2d942019-11-16 04:21:4922class NET_EXPORT_PRIVATE HttpAuthMechanism {
Clark DuVall502f66392019-01-23 16:55:1723 public:
Asanka Herath57f2d942019-11-16 04:21:4924 virtual ~HttpAuthMechanism() = default;
Clark DuVall502f66392019-01-23 16:55:1725
Asanka Herath310ef922019-07-23 19:56:3926 virtual bool Init(const NetLogWithSource& net_log) = 0;
Clark DuVall502f66392019-01-23 16:55:1727
28 // True if authentication needs the identity of the user from Chrome.
29 virtual bool NeedsIdentity() const = 0;
30
31 // True authentication can use explicit credentials included in the URL.
32 virtual bool AllowsExplicitCredentials() const = 0;
33
34 // Parse a received Negotiate challenge.
35 virtual HttpAuth::AuthorizationResult ParseChallenge(
36 HttpAuthChallengeTokenizer* tok) = 0;
37
38 // Generates an authentication token.
39 //
40 // The return value is an error code. The authentication token will be
41 // returned in |*auth_token|. If the result code is not |OK|, the value of
42 // |*auth_token| is unspecified.
43 //
44 // If the operation cannot be completed synchronously, |ERR_IO_PENDING| will
45 // be returned and the real result code will be passed to the completion
46 // callback. Otherwise the result code is returned immediately from this
47 // call.
48 //
49 // If the AndroidAuthNegotiate object is deleted before completion then the
50 // callback will not be called.
51 //
52 // If no immediate result is returned then |auth_token| must remain valid
53 // until the callback has been called.
54 //
55 // |spn| is the Service Principal Name of the server that the token is
56 // being generated for.
57 //
58 // If this is the first round of a multiple round scheme, credentials are
Asanka Herath26b1de82019-05-23 04:03:0459 // obtained using |*credentials|. If |credentials| is nullptr, the default
Clark DuVall502f66392019-01-23 16:55:1760 // credentials are used instead.
61 virtual int GenerateAuthToken(const AuthCredentials* credentials,
62 const std::string& spn,
63 const std::string& channel_bindings,
64 std::string* auth_token,
Asanka Herath310ef922019-07-23 19:56:3965 const NetLogWithSource& net_log,
Clark DuVall502f66392019-01-23 16:55:1766 CompletionOnceCallback callback) = 0;
67
Roman Sorokin040f25f12019-03-06 17:50:2668 // Sets the delegation type allowed on the Kerberos ticket. This allows
69 // certain servers to act as the user, such as an IIS server retrieving data
70 // from a Kerberized MSSQL server.
71 virtual void SetDelegation(HttpAuth::DelegationType delegation_type) = 0;
Clark DuVall502f66392019-01-23 16:55:1772};
73
Asanka Herath3e017f9d2019-11-18 20:53:1874// Factory is just a callback that returns a unique_ptr.
75using HttpAuthMechanismFactory =
76 base::RepeatingCallback<std::unique_ptr<HttpAuthMechanism>(
77 const HttpAuthPreferences*)>;
78
Clark DuVall502f66392019-01-23 16:55:1779} // namespace net
80
Asanka Herath57f2d942019-11-16 04:21:4981#endif // NET_HTTP_HTTP_AUTH_MECHANISM_H_