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
784
784
custom authentication mechanisms such as SPNEGO/Negotiate, OAuth, Bearer tokens, or any other HTTP-based authentication scheme.
785
785
786
-
The {javadoc}/reactor/netty/http/client/HttpClient.html#httpAuthentication-java.util.function.BiPredicate-java.util.function.BiFunction-[`httpAuthentication`]
787
-
method accepts two parameters:
786
+
The framework provides two APIs for HTTP authentication:
788
787
789
-
* A predicate that determines when authentication should be applied (typically by checking the HTTP status code and headers)
790
-
* An authenticator function that applies authentication credentials to the request
<1> Automatically retries on `401 Unauthorized` responses.
830
+
<2> The authenticator adds Basic authentication credentials to the `Authorization` header.
831
+
832
+
=== Custom Authentication with httpAuthenticationWhen
833
+
834
+
When you need custom retry conditions (e.g., checking specific headers or status codes other than 401),
835
+
use the {javadoc}/reactor/netty/http/client/HttpClient.html#httpAuthenticationWhen-java.util.function.BiPredicate-java.util.function.BiFunction-[`httpAuthenticationWhen(BiPredicate, BiFunction)`] method.
836
+
837
+
==== SPNEGO/Negotiate Authentication Example
817
838
818
839
For SPNEGO (Kerberos) authentication, you can implement a custom authenticator using Java's GSS-API:
819
840
@@ -822,7 +843,7 @@ For SPNEGO (Kerberos) authentication, you can implement a custom authenticator u
<1> Check for `407 Proxy Authentication Required` status code.
885
+
<1> Custom predicate checks for `407 Proxy Authentication Required` status code.
875
886
876
887
=== Important Notes
877
888
878
-
* The authenticator function is invoked only when the predicate returns `true`.
889
+
* The authenticator function is invoked only when authentication is needed (on `401` for `httpAuthentication`, or when the predicate returns `true` for `httpAuthenticationWhen`).
879
890
* The authenticator receives the request and remote address, allowing you to customize authentication based on the target server.
880
891
* The authenticator returns a `Mono<Void>` which allows for asynchronous credential retrieval.
881
892
* 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