You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reactor Netty `HttpClient` provides a flexible HTTP authentication framework that allows you to implement
749
749
custom authentication mechanisms such as SPNEGO/Negotiate, OAuth, Bearer tokens, or any other HTTP-based authentication scheme.
750
750
751
-
The {javadoc}/reactor/netty/http/client/HttpClient.html#httpAuthentication-java.util.function.BiPredicate-java.util.function.BiFunction-[`httpAuthentication`]
752
-
method accepts two parameters:
751
+
The framework provides two APIs for HTTP authentication:
753
752
754
-
* A predicate that determines when authentication should be applied (typically by checking the HTTP status code and headers)
755
-
* An authenticator function that applies authentication credentials to the request
<1> Automatically retries on `401 Unauthorized` responses.
795
+
<2> The authenticator adds Basic authentication credentials to the `Authorization` header.
796
+
797
+
=== Custom Authentication with httpAuthenticationWhen
798
+
799
+
When you need custom retry conditions (e.g., checking specific headers or status codes other than 401),
800
+
use the {javadoc}/reactor/netty/http/client/HttpClient.html#httpAuthenticationWhen-java.util.function.BiPredicate-java.util.function.BiFunction-[`httpAuthenticationWhen(BiPredicate, BiFunction)`] method.
801
+
802
+
==== SPNEGO/Negotiate Authentication Example
782
803
783
804
For SPNEGO (Kerberos) authentication, you can implement a custom authenticator using Java's GSS-API:
784
805
@@ -787,7 +808,7 @@ For SPNEGO (Kerberos) authentication, you can implement a custom authenticator u
<1> Check for `407 Proxy Authentication Required` status code.
850
+
<1> Custom predicate checks for `407 Proxy Authentication Required` status code.
840
851
841
852
=== Important Notes
842
853
843
-
* The authenticator function is invoked only when the predicate returns `true`.
854
+
* The authenticator function is invoked only when authentication is needed (on `401` for `httpAuthentication`, or when the predicate returns `true` for `httpAuthenticationWhen`).
844
855
* The authenticator receives the request and remote address, allowing you to customize authentication based on the target server.
845
856
* The authenticator returns a `Mono<Void>` which allows for asynchronous credential retrieval.
846
857
* Authentication is retried only once per request. If authentication fails after retry, the error is propagated to the caller.
Copy file name to clipboardExpand all lines: reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/client/authentication/basic/Application.java
Copy file name to clipboardExpand all lines: reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/client/authentication/spnego/Application.java
Copy file name to clipboardExpand all lines: reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/client/authentication/token/Application.java
0 commit comments