Reputation: 1599
I recently implemented the client_credentials grant for my OAuth2 provider, which is based on Spring security OAuth2.
Than I moved to the client to implement the mechanism there.
I added the @EnableOAuth2Client
annotation and set the following configuration:
spring:
oauth2:
client:
id: myResource
clientId: myClientId
clientSecret: myClientSecret
accessTokenUri: http://localhost:8080/oauth/token
grantType: client_credentials
I'm not really clear on why I need to add the id setting. According to the error message the provider manager needs to support it. This is the error I'm getting:
Unable to obtain a new access token for resource 'myResource'. The provider manager is not configured to support it.
After searching the internet for a while I found that I need to add a global servlet of the DelegatingFilterProxy that delegates to a bean named "oauth2ClientContextFilter"
I found some implementations on how to do that but they all use XML instead of annotation to set their configuration.
<filter>
<filter-name>myFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>myFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
So in conclusion:
Thanks in advance
Upvotes: 0
Views: 1189
Reputation: 1599
So I managed to fix my problem.
After putting this on hold for a while I gave it another try.
It seems that I'm using the wrong ResourceDetails class for my OAuth2RestTemplate.
So replacing
AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
with
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
fixed the problem.
Upvotes: 2