![](/img/trans.png)
[英]Get ID token of a user using custom Admin REST API in Keycloak
[英]Keycloak :REST API call to get access token of a user through admin username and password
我有一個要求,我需要獲取用戶的訪問令牌。
我知道管理員用戶名和密碼,因此可以獲得管理員的訪問令牌。
是否有任何 rest API 可以為使用上述數據的用戶提供訪問令牌?
有兩種獲取訪問令牌的方法。 一個帶有 Rest 客戶端(keycloak Rest API),另一個通過 java keycloak-admin-client 庫。
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();
我有同樣的要求,但是我們不想在上述任何一種方法中傳遞這個明文密碼。 我們正在考慮采用以下方法,但希望建議是否有任何最佳實踐。
第 1 步:在服務器端創建一個安全端點以從 Keycloak 返回令牌。
步驟2 :首先調用此端點時,在客戶端使用一些共享密鑰加密密碼。
步驟 3 。 在接收/服務器端使用相同的共享密鑰解密密碼。
步驟 4 。 在服務器端從 KeyCloak 獲取令牌並返回。
如果有其他更好的方法,我們應該遵循。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.