Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Asanka Herath | 57f2d94 | 2019-11-16 04:21:49 | [diff] [blame] | 5 | #ifndef NET_HTTP_HTTP_AUTH_MECHANISM_H_ |
| 6 | #define NET_HTTP_HTTP_AUTH_MECHANISM_H_ |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 7 | |
Asanka Herath | 3e017f9d | 2019-11-18 20:53:18 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
Avi Drissman | 41c4a41 | 2023-01-11 22:45:37 | [diff] [blame^] | 10 | #include "base/functional/callback_forward.h" |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 11 | #include "net/base/completion_once_callback.h" |
| 12 | #include "net/base/net_export.h" |
| 13 | #include "net/http/http_auth.h" |
| 14 | |
| 15 | namespace net { |
| 16 | |
| 17 | class AuthCredentials; |
| 18 | class HttpAuthChallengeTokenizer; |
Asanka Herath | 3e017f9d | 2019-11-18 20:53:18 | [diff] [blame] | 19 | class HttpAuthPreferences; |
Asanka Herath | 310ef92 | 2019-07-23 19:56:39 | [diff] [blame] | 20 | class NetLogWithSource; |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 21 | |
Asanka Herath | 57f2d94 | 2019-11-16 04:21:49 | [diff] [blame] | 22 | class NET_EXPORT_PRIVATE HttpAuthMechanism { |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 23 | public: |
Asanka Herath | 57f2d94 | 2019-11-16 04:21:49 | [diff] [blame] | 24 | virtual ~HttpAuthMechanism() = default; |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 25 | |
Asanka Herath | 310ef92 | 2019-07-23 19:56:39 | [diff] [blame] | 26 | virtual bool Init(const NetLogWithSource& net_log) = 0; |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 27 | |
| 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 Herath | 26b1de8 | 2019-05-23 04:03:04 | [diff] [blame] | 59 | // obtained using |*credentials|. If |credentials| is nullptr, the default |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 60 | // 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 Herath | 310ef92 | 2019-07-23 19:56:39 | [diff] [blame] | 65 | const NetLogWithSource& net_log, |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 66 | CompletionOnceCallback callback) = 0; |
| 67 | |
Roman Sorokin | 040f25f1 | 2019-03-06 17:50:26 | [diff] [blame] | 68 | // 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 DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 72 | }; |
| 73 | |
Asanka Herath | 3e017f9d | 2019-11-18 20:53:18 | [diff] [blame] | 74 | // Factory is just a callback that returns a unique_ptr. |
| 75 | using HttpAuthMechanismFactory = |
| 76 | base::RepeatingCallback<std::unique_ptr<HttpAuthMechanism>( |
| 77 | const HttpAuthPreferences*)>; |
| 78 | |
Clark DuVall | 502f6639 | 2019-01-23 16:55:17 | [diff] [blame] | 79 | } // namespace net |
| 80 | |
Asanka Herath | 57f2d94 | 2019-11-16 04:21:49 | [diff] [blame] | 81 | #endif // NET_HTTP_HTTP_AUTH_MECHANISM_H_ |