Skip to content

WebClient access token propagation for OIDC logged client #7771

Closed
@codependent

Description

@codependent

Summary

The whole context can be found on Stackoverflow.

Actual Behavior

Despite configuring a WebClient to propagate the access token after OIDC logging of a Spring Boot Oauth2 Client application...

    @Bean
    fun webClient(): WebClient {
        return WebClient.builder()
                .filter(ServletBearerExchangeFilterFunction())
                .build()
    }

The token is not propagated since ServletBearerExchangeFilterFunction doesn't have access to the access token from OAuth2AuthenticationToken:

	private Mono<AbstractOAuth2Token> oauth2Token() {
		return Mono.subscriberContext()
				.flatMap(this::currentAuthentication)
				.filter(authentication -> authentication.getCredentials() instanceof AbstractOAuth2Token)
				.map(Authentication::getCredentials)
				.cast(AbstractOAuth2Token.class);
	}

Expected Behavior

The access token is propagated by the WebClient.

Configuration

https://github.com/codependent/spring-boot-2-oidc-sample

Version

5.2.x

Sample

https://github.com/codependent/spring-boot-2-oidc-sample

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions