私は春のセキュリティでoAuth2を実装しています。しかし、今私はバックエンドからパスワードなしで手動でユーザートークンを作成したい。私はユーザーのユーザー名しか持っていないからです。パスワードなしでoAuth2トークンを手動で作成する必要があります
誰でも私を助けることができます。
私は春のセキュリティでoAuth2を実装しています。しかし、今私はバックエンドからパスワードなしで手動でユーザートークンを作成したい。私はユーザーのユーザー名しか持っていないからです。パスワードなしでoAuth2トークンを手動で作成する必要があります
誰でも私を助けることができます。
Got Answer !!!
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);
accessトークンは必要なトークンです。
ありがとうございました
素晴らしいです、ありがとう! –
ありがとうございます@ChristiaanJanssen。それがあなたのために貴重な場合はまた、upvoteしてください。 –
これまで行っていることはありますか?あなたはまず自分でそれをやろうとしましたか? – aribeiro
通常のユーザーはユーザー/パスワードでログインしており、oAuth2トークンは正常に作成されています。しかし、私はパスワードなしでバックエンドを使って他のユーザートークンを作成する必要があります。 –