Keycloak:REST API调用,用于通过管理员用户名和密码获取用户的访问令牌 [英] Keycloak :REST API call to get access token of a user through admin username and password

查看:1036
本文介绍了Keycloak:REST API调用,用于通过管理员用户名和密码获取用户的访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要获取用户访问令牌的要求.

I have a requirement where I need to get an access token of a user.

我知道管理员的用户名和密码,因此可以获得管理员的访问令牌.

I am aware of the admin username and password and hence can get the access token of the admin.

是否有任何其他API可以为使用上述数据的用户提供访问令牌?

Is there any rest API that can provide me access token a user using the above data?

推荐答案

有两种获取访问令牌的方法.一种带有Rest客户端(keycloak Rest API),另一种则通过java keycloak-admin-client库.

There are two ways to get access token. One with Rest client (keycloak Rest API) and other through java keycloak-admin-client library.

1. Keycloak Rest API:

URI: http://keycloak:8080/auth/realms/myrealm/protocol/openid-connect/token
Type: POST
Content-Type: application/x-www-form-urlencoded
grant_type:password
username:user
password:user_password
client_id:client_id
secret_id:client_secret

2. Keycloak admin client (JAVA)

Keycloak instance = Keycloak.getInstance("http://keycloak:8080/auth", "myrealm", "user", "user_password","client_id", "client_secret");                                                                                                      
TokenManager tokenmanager = instance.tokenManager();
String accessToken = tokenmanager.getAccessTokenString();

这篇关于Keycloak:REST API调用,用于通过管理员用户名和密码获取用户的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆