Class McpAuthInterceptor
- All Implemented Interfaces:
RestCallInterceptor
RestCallInterceptor.
On onInit(RestRequest), sets the Authorization request header to "Bearer " + token,
where token comes from a caller-supplied Supplier.
The OAuth/OIDC flows in juneau-rest-client-mcp-auth plug into this seam by supplying their own token-supplier
implementation (e.g. one that refreshes an expired access token); this class implements no OAuth/OIDC flow itself.
If the supplied token is Authorization
header is set for that request (the call proceeds unauthenticated) - a blank token is never sent as a
credential-less Authorization: Bearer header. If the token supplier itself throws,
RestRequest.run()'s documented interceptor-exception handling aborts the call before it is sent.
Note: when a token is set, enabling FINE/FINEST-level logging on the client's debug
logger (see RestClient.Builder#debugLoggerName(String)) logs the full
outgoing request including all headers, so enabling debug logging on a client using this interceptor will log
the Authorization header (and therefore the bearer token) in plain text.
- Since:
- 10.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic McpAuthInterceptorofStaticBearer(String token) Creates an interceptor that always sends the same static bearer token.voidonInit(RestRequest req) Called before the transport request is built and sent.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.rest.client.RestCallInterceptor
onClose, onConnect
-
Constructor Details
-
McpAuthInterceptor
Constructor.- Parameters:
tokenSupplier- Supplies the bearer token for each request. Must not benull .
-
-
Method Details
-
ofStaticBearer
Creates an interceptor that always sends the same static bearer token.- Parameters:
token- The static bearer token. Must not benull .- Returns:
- A new interceptor. Never
null .
-
onInit
Description copied from interface:RestCallInterceptorCalled before the transport request is built and sent.Use this hook to add headers, modify query parameters, or short-circuit the call.
- Specified by:
onInitin interfaceRestCallInterceptor- Parameters:
req- The request being built. Nevernull .- Throws:
Exception- If the call should be aborted.
-