Skip to content

OAuth2AuthorizedClientArgumentResolver could use OAuth2AuthorizedClientManager registered in context #8700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
benba opened this issue Jun 17, 2020 · 2 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Milestone

Comments

@benba
Copy link
Contributor

benba commented Jun 17, 2020

Describe the bug
OAuth2ClientConfiguration.OAuth2ClientWebMvcSecurityConfiguration does not use the OAuth2AuthorizedClientManager provided by the Spring configuration, therefore @RegisteredOAuth2AuthorizedClient annotated parameters do not use potential customization done in the config.

To Reproduce
Let's say you want to customize the access token response for a refresh like described in the doc

@Bean
public OAuth2AuthorizedClientManager authorizedClientManager(
        ClientRegistrationRepository clientRegistrationRepository,
        OAuth2AuthorizedClientRepository authorizedClientRepository) {

    OAuth2AuthorizedClientProvider authorizedClientProvider =
            OAuth2AuthorizedClientProviderBuilder.builder()
                    .authorizationCode()
                    .refreshToken(configurer -> configurer.accessTokenResponseClient(myCustomAccesTokenResponseClient()))
                    .clientCredentials()
                    .password()
                    .build();

    DefaultOAuth2AuthorizedClientManager authorizedClientManager =
            new DefaultOAuth2AuthorizedClientManager(
                    clientRegistrationRepository, authorizedClientRepository);
    authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);

    return authorizedClientManager;
}

this will not be taken into account when the token is refreshed through a @RegisteredOAuth2AuthorizedClient parameter because OAuth2ClientConfiguration creates a OAuth2AuthorizedClientManager by itself.

Expected behavior
Maybe OAuth2ClientConfiguration.OAuth2ClientWebMvcSecurityConfiguration should inject an OAuth2AuthorizedClientManager and use this one if it exists ? (or allow the customization of the manager created if it is intended to create a different one).

@benba benba added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Jun 17, 2020
@jgrandja jgrandja changed the title @RegisteredOAuth2AuthorizedClient does not use the OAuth2AuthorizedClientManager provided in the Spring configuration OAuth2AuthorizedClientArgumentResolver could use OAuth2AuthorizedClientManager registered in context Jun 22, 2020
@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Jun 22, 2020
@jgrandja
Copy link
Contributor

Thanks for the report @benba.

By default, both OAuth2AuthorizedClientArgumentResolver and ServletOAuth2AuthorizedClientExchangeFilterFunction create default OAuth2AuthorizedClientManager. Instead of using @RegisteredOAuth2AuthorizedClient to refresh the access token, you can configure ServletOAuth2AuthorizedClientExchangeFilterFunction to use your custom OAuth2AuthorizedClientManager for refreshing the access token. Of course, this is only applicable if you're using WebClient.

Regardless, I'll add this to the backlog as an enhancement.

@jgrandja
Copy link
Contributor

Related #8669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants