第8章 認可サービス
Red Hat build of Keycloak の Authorization Services は、OAuth2 や User-Managed Access 仕様などのよく知られた標準規格の上にビルドされています。
OAuth2 クライアント (フロントエンドアプリケーションなど) は、トークンエンドポイントを使用してサーバーからアクセストークンを取得し、その同じトークンを使用してリソースサーバー (バックエンドサービスなど) で保護されたリソースにアクセスすることができます。同様に、Red Hat build of Keycloak の Authorization Services は OAuth2 の拡張機能を提供し、要求されたリソースまたはスコープに関連するすべてのポリシーの処理に基づいてアクセストークンを発行できます。つまり、リソースサーバーは、サーバーによって付与されるパーミッションに基づいて保護されているリソースへのアクセスを強制でき、アクセストークンによって保持されます。Red Hat build of Keycloak の Authorization Services では、パーミッションのあるアクセストークンは Requesting Party Token (RPT) と呼ばれます。
RPT の発行に加えて、Red Hat build of Keycloak の Authorization Services は、リソースサーバーが保護されたリソース、スコープ、パーミッション、ポリシーを管理できるようにする一連の RESTful エンドポイントも提供します。これは、きめ細かな認可をサポートするために、開発者がこれらの機能をアプリケーションに拡張または統合する際に役立ちます。
8.1. 認可サービスエンドポイントおよびメタデータの検出
Red Hat build of Keycloak では、ディスカバリードキュメントが提供されています。クライアントは、エンドポイントの場所や機能などを含め、Red Hat build of Keycloak Authorization Services と対話するために必要なすべての情報をここから取得できます。
検出ドキュメントは、以下から取得できます。
curl -X GET \ http://${host}:${port}/realms/${realm}/.well-known/uma2-configuration
curl -X GET \
http://${host}:${port}/realms/${realm}/.well-known/uma2-configuration
${host}:${port}
は、Red Hat build of Keycloak が実行されているホスト名 (または IP アドレス) とポートで、${realm}
は Red Hat build of 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" }
{
// 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"
}
これらの各エンドポイントは、特定の機能セットを公開します。
token_endpoint
urn:ietf:params:oauth:grant-type:uma-ticket
付与タイプをサポートする OAuth2 準拠のトークンエンドポイント。このエンドポイントを介して、クライアントは認可要求を送信し、Red Hat build of Keycloak によって付与されたすべての権限を持つ RPT を取得できます。token_introspection_endpoint
OAuth2 準拠のトークンイントロスペクションエンドポイント。クライアントがサーバーにクエリーして RPT のアクティブな状態を判断し、Red Hat build of Keycloak が付与するパーミッションなどのトークンに関連付けられた他の情報を決定します。
resource_registration_endpoint
リソースサーバーが保護されるリソースおよびスコープを管理するために使用できる UMA 準拠の Resource Registration Endpoint。このエンドポイントは、Red Hat build of Keycloak のリソースおよびスコープの作成、読み取り、更新、削除の操作を行います。
permission_endpoint
リソースサーバーがパーミッションチケットを管理するのに使用できる UMA 準拠のパーミッションエンドポイント。このエンドポイントは、Red Hat build of Keycloak でパーミッションチケットを作成、読み取り、更新、削除する操作を提供します。