Thanks to this comment, I managed to tidy up my implementation a little bit. So no more need for specifying encode/decoder nonsense, or having to manually build my Feign client.

The docs here provide some info, but as is typical they are a bit thin on concrete examples, so perhaps the below will help someone else. Note: I'm using spring boot, and including feign like so in build.gradle implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

First, create the RequestInterceptor like so:

import org.springframework.context.annotation.Bean;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.jwt.Jwt;

import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;

/**
 * A Feign configuration to add the incoming Bearer token to an outgoing feign client request.
 * Only annotate this class with "@Configuration" if you want this interceptor to apply globally to all your Feign clients.
 * Otherwise you risk exposing the auth token to a third party, or adding it unnecessarily to requests that don't need it.
 */
@Slf4j
public class BearerAuthFeignConfig {

    @Bean
    public RequestInterceptor bearerAuthRequestInterceptor() {
        return requestTemplate -> {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (authentication != null && authentication.getPrincipal() instanceof Jwt) {
                Jwt jwt = (Jwt) authentication.getPrincipal();
                requestTemplate.header("Authorization", "Bearer " + jwt.getTokenValue());
            } else {
                log.error("Unable to add Authoriation header to Feign requestTemplate");
            }
        };
    }
}

Then when declaring your feign client, pass the configuration

@FeignClient(
    name = "my-client-that-needs-the-auth",
    configuration = BearerAuthFeignConfig.class,
    url = "http://whatever.com"
)
public interface PlayerManagementClient {
  ...

You'll also need the @EnableFeignClients annotation on your @SpringBootApplication class

Answer from BoomShaka on Stack Overflow
🌐
Chrome Web Store
chromewebstore.google.com › detail › request-interceptor › bfgblailifedppfilabonohepkofbkpm
Request Interceptor - Chrome Web Store
Intercept and modify network requests: headers, query params, delay, response body, custom script/CSS injection.
🌐
Javadoc.io
javadoc.io › doc › io.github.openfeign › feign-core › 10.12 › feign › RequestInterceptor.html
RequestInterceptor - feign-core 10.12 javadoc
Bookmarks · Latest version of io.github.openfeign:feign-core · https://javadoc.io/doc/io.github.openfeign/feign-core · Current version 10.12 · https://javadoc.io/doc/io.github.openfeign/feign-core/10.12 · package-list path (used for javadoc generation -link option) · https://javadoc....
Top answer
1 of 1
5

Thanks to this comment, I managed to tidy up my implementation a little bit. So no more need for specifying encode/decoder nonsense, or having to manually build my Feign client.

The docs here provide some info, but as is typical they are a bit thin on concrete examples, so perhaps the below will help someone else. Note: I'm using spring boot, and including feign like so in build.gradle implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

First, create the RequestInterceptor like so:

import org.springframework.context.annotation.Bean;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.jwt.Jwt;

import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;

/**
 * A Feign configuration to add the incoming Bearer token to an outgoing feign client request.
 * Only annotate this class with "@Configuration" if you want this interceptor to apply globally to all your Feign clients.
 * Otherwise you risk exposing the auth token to a third party, or adding it unnecessarily to requests that don't need it.
 */
@Slf4j
public class BearerAuthFeignConfig {

    @Bean
    public RequestInterceptor bearerAuthRequestInterceptor() {
        return requestTemplate -> {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (authentication != null && authentication.getPrincipal() instanceof Jwt) {
                Jwt jwt = (Jwt) authentication.getPrincipal();
                requestTemplate.header("Authorization", "Bearer " + jwt.getTokenValue());
            } else {
                log.error("Unable to add Authoriation header to Feign requestTemplate");
            }
        };
    }
}

Then when declaring your feign client, pass the configuration

@FeignClient(
    name = "my-client-that-needs-the-auth",
    configuration = BearerAuthFeignConfig.class,
    url = "http://whatever.com"
)
public interface PlayerManagementClient {
  ...

You'll also need the @EnableFeignClients annotation on your @SpringBootApplication class

Find elsewhere
🌐
Medium
medium.com › but-it-works-on-my-machine › what-is-spring-boot-request-interceptor-and-how-to-use-it-7fd85f3df7f7
What is Spring Boot Request Interceptor and How to Use It? | by Ahmet Emre DEMİRŞEN | @Override | Medium
April 26, 2026 - Creating the RequestInterceptor Class · Test and Track operations · In order to use the Request Interceptor in our project, we first need to add the necessary configurations to our Config class. If we don’t have a Config class… · 524 followers · ·Last published Sep 2, 2026 ·
🌐
Spring
docs.spring.io › spring-framework › docs › current › javadoc-api › org › springframework › http › client › ClientHttpRequestInterceptor.html
ClientHttpRequestInterceptor (Spring Framework 7.0.9 API)
A typical implementation of this method would follow the following pattern: Examine the request and body. Optionally wrap the request to filter HTTP attributes. Optionally modify the body of the request. either execute the request using ClientHttpRequestExecution.execute(HttpRequest, byte[]) ...
🌐
Medium
medium.com › @ucgorai › spring-boot-request-interceptors-middleware-for-your-controllers-564f614eb5c8
Spring Boot Request Interceptors: Middleware for Your Controllers | by Uma Charan Gorai | Medium
December 12, 2024 - In Spring Boot, a Request Interceptor is a mechanism used to intercept incoming HTTP requests and outgoing HTTP responses. It allows…
🌐
Oatpp
oatpp.io › api › latest › oatpp › web › server › interceptor › RequestInterceptor
RequestInterceptor.hpp | Oat++
namespace oatpp { namespace web { namespace server { namespace interceptor { class RequestInterceptor {} }}}}
🌐
GeeksforGeeks
geeksforgeeks.org › advance java › spring-boot-interceptor
Spring Boot - Interceptor - GeeksforGeeks
July 23, 2025 - @Override the method - addInterceptors(InterceptorRegistry registry): This tells the InterceptorRegistry to register the provided class as the Interceptor. In our case it - is 'RequestInterceptor'.
🌐
CDRouter
support.qacafe.com › packet-viewer › deployment-guide › request-interceptor
Request Interceptor | QA Cafe Support
Introduction The server-side request interceptor, implemented as a TypeScript module, allows developers to intercept and modify outgoing HTTP GET requests for remote PCAPs before they are sent.
🌐
GitHub
github.com › spring-cloud › spring-cloud-openfeign › issues › 393
RequestInterceptor should support sort by order · Issue #393 · spring-cloud/spring-cloud-openfeign
August 17, 2020 - Map<String, RequestInterceptor> requestInterceptors = context .getInstances(this.contextId, RequestInterceptor.class); if (requestInterceptors != null) { builder.requestInterceptors(requestInterceptors.values()); }
Author: spring-cloud
🌐
Alamofire
alamofire.github.io › Alamofire › Protocols › RequestInterceptor.html
RequestInterceptor Protocol Reference
@preconcurrency public static func interceptor(adapters: [any RequestAdapter] = [], retriers: [any RequestRetrier] = [], interceptors: [any RequestInterceptor] = []) -> Interceptor
🌐
NestJS
docs.nestjs.com › interceptors
Interceptors | NestJS - A progressive Node.js framework
An interceptor is a class annotated with the @Injectable() decorator that implements the NestInterceptor interface.
🌐
SmartBear Community
community.smartbear.com › smartbear community › swagger open source › swagger open source tools questions
requestInterceptor with Python | SmartBear Community
app = FastAPI( swagger_ui_parameters={"requestSnippetsEnabled": True,"persistAuthorization":True, "requestInterceptor": """ (req) => { // Modify the request object as needed req.headers['Authorization'] = 'Bearer <your_access_token>'; return req; } """ } )
🌐
Spring
docs.spring.io › spring-cloud-openfeign › docs › current › reference › html
Spring Cloud OpenFeign
This replaces the SpringMvcContract with feign.Contract.Default and adds a RequestInterceptor to the collection of RequestInterceptor.