use of org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class DefaultOAuth2RequestAuthenticator method authenticate.
@Override
public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest request) {
OAuth2AccessToken accessToken = clientContext.getAccessToken();
if (accessToken == null) {
throw new AccessTokenRequiredException(resource);
}
String tokenType = accessToken.getTokenType();
if (!StringUtils.hasText(tokenType)) {
// we'll assume basic bearer token type if none is specified.
tokenType = OAuth2AccessToken.BEARER_TYPE;
}
request.getHeaders().set("Authorization", String.format("%s %s", tokenType, accessToken.getValue()));
}
use of org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class ClientApplication method resource.
@Bean
protected OAuth2ProtectedResourceDetails resource() {
AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
resource.setAccessTokenUri(tokenUrl);
resource.setUserAuthorizationUri(authorizeUrl);
resource.setClientId("my-trusted-client");
return resource;
}
use of org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class ClientApplication method resource.
@Bean
protected OAuth2ProtectedResourceDetails resource() {
AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
resource.setAccessTokenUri(tokenUrl);
resource.setUserAuthorizationUri(authorizeUrl);
resource.setClientId("my-trusted-client");
return resource;
}
use of org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails in project spring-security-oauth2-google by skate056.
the class OAuth2SecurityConfiguration method googleResource.
@Bean
@Scope("session")
public OAuth2ProtectedResourceDetails googleResource() {
AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
details.setId("google-oauth-client");
details.setClientId(env.getProperty("google.client.id"));
details.setClientSecret(env.getProperty("google.client.secret"));
details.setAccessTokenUri(env.getProperty("google.accessTokenUri"));
details.setUserAuthorizationUri(env.getProperty("google.userAuthorizationUri"));
details.setTokenName(env.getProperty("google.authorization.code"));
String commaSeparatedScopes = env.getProperty("google.auth.scope");
details.setScope(parseScopes(commaSeparatedScopes));
details.setPreEstablishedRedirectUri(env.getProperty("google.preestablished.redirect.url"));
details.setUseCurrentUri(false);
details.setAuthenticationScheme(AuthenticationScheme.query);
details.setClientAuthenticationScheme(AuthenticationScheme.form);
return details;
}
use of org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class OAuth2ContextSetup method createRestTemplate.
private OAuth2RestTemplate createRestTemplate(OAuth2ProtectedResourceDetails resource, AccessTokenRequest request) {
OAuth2ClientContext context = new DefaultOAuth2ClientContext(request);
OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context);
setupConnectionFactory(client);
client.setErrorHandler(new DefaultResponseErrorHandler() {
// Pass errors through in response entity for status code analysis
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
});
if (accessTokenProvider != null) {
client.setAccessTokenProvider(accessTokenProvider);
}
return client;
}
Aggregations