gpt4 book ai didi

java - 是否可以通过 Keycloak 中的 REST API 检查用户是否具有 Activity/有效 session ?

转载 作者:行者123 更新时间:2023-12-05 04:12:31 31 4
gpt4 key购买 nike

是否可以通过 REST API 检查用户是否有 Activity/有效 session ?

我正在使用 Java REST 管理客户端。我看到了

返回的UserSessionRepresentation
List<UserSessionRepresentation> usr = Keycloak.realm("realmId").users().get("userId").getUserSessions();

但是UserSessionRepresentation 没有我想要的信息。可能吗?

最佳答案

您可以使用此地址检查您的 session :

http://keycloakAddressAndPort/auth/realms/develop/protocol/openid-connect/userinfo

如果您的 session 不正常,您会看到此响应(http 状态代码 401):

{
"error": "invalid_request",
"error_description": "User session not found or doesn't have client attached on it"
}

如果没问题,您会看到类似这样的内容(http 状态代码 200):

{
"sub": "c0c25095-63e7-471d-a39e-f3b157c91fd7",
"email_verified": true,
"name": "Amir Azizkhani",
"preferred_username": "a.azizkhani@...",
"given_name": "Amir",
"family_name": "Azizkhani",
"email": "a.azizkhani@...."
}

完整的 postman json:

{
"info": {
"_postman_id": "77ce65c3-948a-4b3d-a97b-b11cd00c593b",
"name": "Spring Keycloak",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [

{
"name": "openid-connect/userinfo",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "eyJhbGciOiJSUzI1NiIsInR5cC...",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "accept",
"value": "application/json"
}
],
"url": {
"raw": "http://192.168.131.33:8080/auth/realms/develop/protocol/openid-connect/userinfo",
"protocol": "http",
"host": [
"192",
"168",
"131",
"33"
],
"port": "8080",
"path": [
"auth",
"realms",
"develop",
"protocol",
"openid-connect",
"userinfo"
]
},
"description": "Dont forget to set Bearer value obtains from token request"
},
"response": []
}
]
}

关于java - 是否可以通过 Keycloak 中的 REST API 检查用户是否具有 Activity/有效 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40163736/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com