Spring OAuth2 - Manually creating an access token in the token store

后端 未结 7 932
天涯浪人
天涯浪人 2020-12-07 17:00

I have a situation where I would like to create an access token myself (so not through the usual process). I have come up with something like this:

@Inject
p         


        
相关标签:
7条回答
  • 2020-12-07 17:57

    Here is how to generate a Token using the TokenEndpoint interface (used to expose REST service) :

    @Inject
    private TokenEndpoint tokenEndpoint;
    
    public ResponseEntity<?> getToken(Principal principal) {
    
            HashMap<String, String> parameters = new HashMap<String, String>();
            parameters.put("client_id", "appid");
            parameters.put("client_secret", "myOAuthSecret");
            parameters.put("grant_type", "password");
            parameters.put("password", myUser.getPassword());
            parameters.put("scope", "read write");
            parameters.put("username", myUser.getLogin());
    
            return tokenEndpoint.getAccessToken(principal, parameters);
    }
    
    0 讨论(0)
提交回复
热议问题