Spring Security OAuth - Provider Manager is Not Configured for Null Resource
The real reason is, you are using ResourceOwnerPasswordResourceDetails
for a "client_credentials"
access token request. We cannot interchange ResourceOwnerPasswordResourceDetails
and ClientCredentialsResourceDetails
.
In ClientCredentialsResourceDetails
you need to set AccessTokenUri, ClientId, ClientSecret
and grantType
.In ResourceOwnerPasswordResourceDetails
, you need to provide Username and Password
along with AccessTokenUri, ClientId, ClientSecret
and GrantType
.
(Some authserver do accept password
token request without username and password
.. But I would say it is wrong)
This is what i use:
@Beanpublic RestTemplate oAuthRestTemplate() { ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails(); resourceDetails.setId("1"); resourceDetails.setClientId(oAuth2ClientId); resourceDetails.setClientSecret(oAuth2ClientSecret); resourceDetails.setAccessTokenUri(accessTokenUri); OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, oauth2ClientContext); return restTemplate;}
The correct headers will be set bij the framework, but the username/password will be base64 encodes as Authorization header (basic authentication). This is the OAuth2 spec for a client_credentials grant.
Check if the api supports the spec:
curl -X POST \'https://api.app.com/v1/oauth/token' \-i -u 'client:secret' \-H 'Content-Type: application/x-www-form-urlencoded' \-d 'grant_type=client_credentials'
If you need to send the username & password as data instead of authorisation header, you can add resourceDetails.setAuthenticationScheme(AuthenticationScheme.form);
this should set de username & password as data
This could be oocured beacuse server doest not recognize the content type you posting to that specific url. In your CURL request try include the 'content-type: application/x-www-form-urlencoded' for custom conrtroller using http headers.
Also you have not set username and password for resourceDetails.resourceDetails.setUserName("user");resourceDetails.setUserName("password");
if those does not work try to extract the request that Encoded with application/x-www-form-urlencoded and pass it as a string via RestTemplate and you can get the token.
Let me know any if you need additional support.
Try the code below that is giving token as and string response.