Skip to content

Add ServletOAuth2AuthorizedClientExchangeFilterFunction #5545

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
rwinch opened this issue Jul 20, 2018 · 0 comments
Closed

Add ServletOAuth2AuthorizedClientExchangeFilterFunction #5545

rwinch opened this issue Jul 20, 2018 · 0 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
Milestone

Comments

@rwinch
Copy link
Member

rwinch commented Jul 20, 2018

Summary

This will be integration for working with WebClient and OAuth in a Servlet based environment.

// configuration
@Bean
WebClient webClient(OAuth2AuthorizedClientRepository repository) {
	ServletOAuth2AuthorizedClientExchangeFilterFunction filter = 
			new ServletOAuth2AuthorizedClientExchangeFilterFunction(repository);
	return WebClient.builder()
			.apply(filter.oauth2Configuration())
			.build();
}

// explicitly provide the OAuth2AuthorizedClient via attributes
@GetMapping("/github/explicit")
Mono<String> explicitAuthorizedClient(@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient) {
	return this.webClient.get()
			.uri("https://api.github.com/user")
			.attributes(oauth2AuthorizedClient(authorizedClient))
			.retrieve()
			.bodyToMono(String.class);
}

// gets the OAuth2AuthorizedClient from the current Authentication when using oauth2Login
@GetMapping("/github/authentication")
Mono<String> implicitFromAuthentication() {
	return this.webClient.get()
			.uri("https://api.github.com/user")
			.retrieve()
			.bodyToMono(String.class);
}

// look up the OAuth2AuthorizedClient using the client registration id
@GetMapping("/github/client-registration-id")
Mono<String> githubClientRegistrationId() {
	return this.webClient.get()
			.uri("https://api.github.com/user")
			.attributes(clientRegistrationId("github"))
			.retrieve()
			.bodyToMono(String.class);
}
@rwinch rwinch added Reactive in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) labels Jul 20, 2018
@rwinch rwinch added this to the 5.1.0.M2 milestone Jul 20, 2018
@rwinch rwinch self-assigned this Jul 20, 2018
@rwinch rwinch closed this as completed in 1b79bbe Jul 20, 2018
rwinch added a commit that referenced this issue Jul 20, 2018
…ction

This will allow us to break up
ServletOAuth2AuthorizedClientExchangeFilterFunction into multiple
components if we decide to later.

Issue: gh-5545
rwinch added a commit that referenced this issue Jul 22, 2018
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)
Projects
None yet
Development

No branches or pull requests

1 participant