org.springframework.security.oauth2.client.endpoint.DefaultClientCredentialsTokenResponseClient Java Examples

The following examples show how to use org.springframework.security.oauth2.client.endpoint.DefaultClientCredentialsTokenResponseClient. 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: EurekaOAuth2ClientFilterAdapter.java    From spring-cloud-services-starters with Apache License 2.0 5 votes vote down vote up
@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException {
	Instant now = Clock.systemUTC().instant();
	if (accessToken == null || now.isAfter(accessToken.getExpiresAt())) {
		DefaultClientCredentialsTokenResponseClient tokenResponseClient = new DefaultClientCredentialsTokenResponseClient();
		OAuth2ClientCredentialsGrantRequest clientCredentialsGrantRequest = new OAuth2ClientCredentialsGrantRequest(
				clientRegistration);
		accessToken = tokenResponseClient.getTokenResponse(clientCredentialsGrantRequest).getAccessToken();
	}

	cr.getHeaders().add(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken.getTokenValue());

	return getNext().handle(cr);
}
 
Example #2
Source File: OAuth2AuthorizedClientHttpRequestInterceptor.java    From spring-cloud-services-starters with Apache License 2.0 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {
	Instant now = Clock.systemUTC().instant();
	if (accessToken == null || now.isAfter(accessToken.getExpiresAt())) {
		DefaultClientCredentialsTokenResponseClient tokenResponseClient = new DefaultClientCredentialsTokenResponseClient();
		OAuth2ClientCredentialsGrantRequest clientCredentialsGrantRequest = new OAuth2ClientCredentialsGrantRequest(
				clientRegistration);
		accessToken = tokenResponseClient.getTokenResponse(clientCredentialsGrantRequest).getAccessToken();
	}

	request.getHeaders().add(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken.getTokenValue());
	return execution.execute(request, body);
}
 
Example #3
Source File: DataFlowConfiguration.java    From composed-task-runner with Apache License 2.0 4 votes vote down vote up
@Bean
OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient() {
	return new DefaultClientCredentialsTokenResponseClient();
}
 
Example #4
Source File: CredHubRestTemplateFactory.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
private static OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> buildTokenResponseClient(
		ClientHttpRequestFactory clientHttpRequestFactory) {
	DefaultClientCredentialsTokenResponseClient tokenResponseClient = new DefaultClientCredentialsTokenResponseClient();
	tokenResponseClient.setRestOperations(createTokenServerRestTemplate(clientHttpRequestFactory));
	return tokenResponseClient;
}
 
Example #5
Source File: DataFlowClientAutoConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient() {
	return new DefaultClientCredentialsTokenResponseClient();
}
 
Example #6
Source File: DataFlowConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient() {
	return new DefaultClientCredentialsTokenResponseClient();
}