问题
With this reference to the Spring OAuth2 Client docs:
And the following section:
If you desparately need password grants to work from a Java client, then use the same mechanism to configure your OAuth2RestTemplate and add the credentials to the AccessTokenRequest (which is a Map and is ephemeral) not the ResourceOwnerPasswordResourceDetails (which is shared between all access tokens).
How can the credentials be added to the AccessTokenRequest? Or more generally, how can I get a reference to the AccessTokenRequest or OAuth2ClientContext for the specific user of the request.
The reason why I need this is to avoid the UserRedirectRequiredException and the requirement to redirect to the authorize URL, as the Rest API I am accessing does not have a login page, but just a restful login api.
Supposedly the OAuth2ClientContextFilter should store the current request and context but I can't see how.
回答1:
Accessing the AccessTokenRequest
:
@Autowired
OAuth2RestTemplate restTemplate;
public void doSomething() {
AccessTokenRequest request =
restTemplate.getOAuth2ClientContext().getAccessTokenRequest();
...
}
来源:https://stackoverflow.com/questions/29649282/spring-security-oauth2-adding-credentials-to-the-accesstokenrequest