Got Odpowiedź !!!
HashMap<String, String> authorizationParameters = new HashMap<String, String>();
authorizationParameters.put("scope", "read");
authorizationParameters.put("username", "user");
authorizationParameters.put("client_id", "client_id");
authorizationParameters.put("grant", "password");
Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Set<String> responseType = new HashSet<String>();
responseType.add("password");
Set<String> scopes = new HashSet<String>();
scopes.add("read");
scopes.add("write");
OAuth2Request authorizationRequest = new OAuth2Request(
authorizationParameters, "Client_Id",
authorities, true,scopes, null, "",
responseType, null);
User userPrincipal = new User("user", "", true, true, true, true, authorities);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
userPrincipal, null, authorities);
OAuth2Authentication authenticationRequest = new OAuth2Authentication(
authorizationRequest, authenticationToken);
authenticationRequest.setAuthenticated(true);
OAuth2AccessToken accessToken = tokenService
.createAccessToken(authenticationRequest);
accessToken jest tokenem, który chcesz.
Dzięki
Co zrobiłeś do tej pory? Czy najpierw próbowałeś to zrobić sam? – aribeiro
Normalny użytkownik to login z hasłem użytkownika i token oAuth2 został pomyślnie utworzony. Ale muszę utworzyć inny token użytkownika za pomocą backendu bez hasła. –