第 8 章 授权服务


红帽构建的 Keycloak 授权服务基于众所周知的标准构建,如 OAuth2 和用户管理的访问规范。

OAuth2 客户端(如前端应用)可以使用令牌端点从服务器获取访问令牌,并使用这些令牌访问受资源服务器保护的资源(如后端服务)。同样,红帽构建的 Keycloak 授权服务为 OAuth2 提供扩展,以允许根据请求的资源或范围关联的所有策略来处理访问令牌。这意味着资源服务器可以根据服务器授予的权限强制访问其受保护的资源,并由访问令牌保存。在红帽构建的 Keycloak 授权服务中,具有权限的访问令牌称为 请求第三方令牌或 RPT。

除了 RPT 的颁发之外,红帽构建的 Keycloak 授权服务还提供了一组 RESTful 端点,允许资源服务器管理其受保护的资源、范围、权限和策略,帮助开发人员将这些功能扩展或集成到其应用程序中,以支持精细的授权。

8.1. 发现授权服务端点和元数据

Red Hat build of Keycloak 提供了一个发现文档,客户端可以从中获取与 Keycloak 授权服务(包括端点位置和功能)交互的所有必要信息。

发现文档可从以下位置获取:

curl -X GET \
  http://${host}:${port}/realms/${realm}/.well-known/uma2-configuration
Copy to Clipboard Toggle word wrap

其中 ${host}:${port} 是运行红帽构建的 Keycloak 的主机名(或 IP 地址)和端口,${realm} 是红帽构建的 Keycloak 中域名。

因此,您应该收到响应,如下所示:

{

    // some claims are expected here

    // these are the main claims in the discovery document about Authorization Services endpoints location
    "token_endpoint": "http://${host}:${port}/realms/${realm}/protocol/openid-connect/token",
    "token_introspection_endpoint": "http://${host}:${port}/realms/${realm}/protocol/openid-connect/token/introspect",
    "resource_registration_endpoint": "http://${host}:${port}/realms/${realm}/authz/protection/resource_set",
    "permission_endpoint": "http://${host}:${port}/realms/${realm}/authz/protection/permission",
    "policy_endpoint": "http://${host}:${port}/realms/${realm}/authz/protection/uma-policy"
}
Copy to Clipboard Toggle word wrap

每个端点都公开一组特定的功能:

  • token_endpoint

    支持 urn:ietf:params:grant-type:uma-ticket 授权类型的 OAuth2 兼容令牌端点。通过此端点客户端可以发送授权请求并获取 RPT,以及由红帽构建 Keycloak 授予的所有权限的 RPT。

  • token_introspection_endpoint

    与 OAuth2 兼容令牌内省端点,客户端可以使用查询服务器来确定 RPT 的活动状态,并确定与令牌关联的任何其他信息,如红帽构建 Keycloak 授予的权限。

  • resource_registration_endpoint

    符合 UMA 的资源注册端点,资源服务器可用于管理其受保护的资源和范围。此端点提供在红帽构建的 Keycloak 中创建、读取、更新和删除资源和范围的操作。

  • permission_endpoint

    一个 UMA 兼容权限端点,资源服务器可以使用它来管理权限票据。此端点提供在红帽构建的 Keycloak 中创建、读取、更新和删除权限票据的操作。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat