Java Code Examples for org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager#authorize()
The following examples show how to use
org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager#authorize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigCommands.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
private ClientHttpRequestInterceptor bearerTokenResolvingInterceptor( OAuth2ClientProperties properties, String username, String password, String clientRegistrationId) { ClientRegistrationRepository shellClientRegistrationRepository = shellClientRegistrationRepository(properties); OAuth2AuthorizedClientService shellAuthorizedClientService = shellAuthorizedClientService(shellClientRegistrationRepository); OAuth2AuthorizedClientManager authorizedClientManager = authorizedClientManager( shellClientRegistrationRepository, shellAuthorizedClientService); if (properties.getRegistration() != null && properties.getRegistration().size() == 1) { // if we have only one, use that clientRegistrationId = properties.getRegistration().entrySet().iterator().next().getKey(); } OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest.withClientRegistrationId(clientRegistrationId) .principal(DEFAULT_PRINCIPAL) .attribute(OAuth2AuthorizationContext.USERNAME_ATTRIBUTE_NAME, username) .attribute(OAuth2AuthorizationContext.PASSWORD_ATTRIBUTE_NAME, password) .build(); return (request, body, execution) -> { OAuth2AuthorizedClient authorizedClient = authorizedClientManager.authorize(authorizeRequest); request.getHeaders().setBearerAuth(authorizedClient.getAccessToken().getTokenValue()); return execution.execute(request, body); }; }
Example 2
Source File: DataFlowClientAutoConfiguration.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
private ClientHttpRequestInterceptor bearerTokenResolvingInterceptor( OAuth2ClientProperties properties, String username, String password, String clientRegistrationId) { ClientRegistrationRepository shellClientRegistrationRepository = shellClientRegistrationRepository(properties); OAuth2AuthorizedClientService shellAuthorizedClientService = shellAuthorizedClientService(shellClientRegistrationRepository); OAuth2AuthorizedClientManager authorizedClientManager = authorizedClientManager( shellClientRegistrationRepository, shellAuthorizedClientService); if (properties.getRegistration() != null && properties.getRegistration().size() == 1) { // if we have only one, use that clientRegistrationId = properties.getRegistration().entrySet().iterator().next().getKey(); } OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest.withClientRegistrationId(clientRegistrationId) .principal(DEFAULT_PRINCIPAL) .attribute(OAuth2AuthorizationContext.USERNAME_ATTRIBUTE_NAME, username) .attribute(OAuth2AuthorizationContext.PASSWORD_ATTRIBUTE_NAME, password) .build(); return (request, body, execution) -> { OAuth2AuthorizedClient authorizedClient = authorizedClientManager.authorize(authorizeRequest); request.getHeaders().setBearerAuth(authorizedClient.getAccessToken().getTokenValue()); return execution.execute(request, body); }; }