Spring Security Oauth2 - Adding credentials to the AccessTokenRequest

北战南征 提交于 2019-12-11 13:57:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!