Skip to content

Commit 4d4d238

Browse files
authored
fix docs for keycloak_openid_client_permissions, add example (#553)
1 parent 6b93daa commit 4d4d238

File tree

2 files changed

+73
-41
lines changed

2 files changed

+73
-41
lines changed

docs/resources/openid_client_permission.md

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,47 @@
22

33
Allows you to manage all openid client Scope Based Permissions.
44

5-
This is part of a preview keycloak feature. You need to enable this feature to be able to use this resource.
6-
More information about enabling the preview feature can be found here: https://www.keycloak.org/docs/latest/securing_apps/index.html#_token-exchange
5+
This is part of a preview keycloak feature. You need to enable this feature to be able to use this resource. More
6+
information about enabling the preview feature can be found
7+
here: https://www.keycloak.org/docs/latest/securing_apps/index.html#_token-exchange
78

89
When enabling Openid Client Permissions, Keycloak does several things automatically:
10+
911
1. Enable Authorization on build-in realm-management client
10-
1. Create scopes "view", "manage", "configure", "map-roles", "map-roles-client-scope", "map-roles-composite", "token-exchange"
12+
1. Create scopes "view", "manage", "configure", "map-roles", "map-roles-client-scope", "map-roles-composite", "
13+
token-exchange"
1114
1. Create a resource representing the openid client
1215
1. Create all scope based permission for the scopes and openid client resource
1316

14-
If the realm-management Authorization is not enable, you have to ceate a dependency (`depends_on`) with the policy and the openid client.
17+
If the realm-management Authorization is not enable, you have to ceate a dependency (`depends_on`) with the policy and
18+
the openid client.
1519

1620
### Example Usage
1721

1822
```hcl
1923
resource "keycloak_realm" "realm" {
20-
realm = "realm"
24+
realm = "realm"
2125
}
2226
2327
resource "keycloak_openid_client" "my_openid_client" {
24-
realm_id = keycloak_realm.realm.id
25-
name = "my_openid_client"
26-
client_id = "my_openid_client"
27-
client_secret = "secret"
28-
access_type = "CONFIDENTIAL"
29-
standard_flow_enabled = true
30-
valid_redirect_uris = [
31-
"http://localhost:8080/*",
32-
]
28+
realm_id = keycloak_realm.realm.id
29+
name = "my_openid_client"
30+
client_id = "my_openid_client"
31+
client_secret = "secret"
32+
access_type = "CONFIDENTIAL"
33+
standard_flow_enabled = true
34+
valid_redirect_uris = [
35+
"http://localhost:8080/*",
36+
]
3337
}
3438
3539
data "keycloak_openid_client" "realm_management" {
3640
realm_id = keycloak_realm.realm.id
37-
client_id = "realm-management"
38-
}
41+
client_id = "realm-management"
42+
}
3943
4044
resource keycloak_user test {
41-
realm_id = "${keycloak_realm.realm.id}"
45+
realm_id = keycloak_realm.realm.id
4246
username = "test-user"
4347
4448
@@ -47,27 +51,30 @@ resource keycloak_user test {
4751
}
4852
4953
resource keycloak_openid_client_user_policy test {
50-
resource_server_id = "${data.keycloak_openid_client.realm_management.id}"
51-
realm_id = "${keycloak_realm.realm.id}"
52-
name = "client_user_policy_test"
53-
users = ["${keycloak_user.test.id}"]
54-
logic = "POSITIVE"
55-
decision_strategy = "UNANIMOUS"
56-
depends_on = [
54+
resource_server_id = data.keycloak_openid_client.realm_management.id
55+
realm_id = keycloak_realm.realm.id
56+
name = "client_user_policy_test"
57+
users = [
58+
keycloak_user.test.id
59+
]
60+
logic = "POSITIVE"
61+
decision_strategy = "UNANIMOUS"
62+
depends_on = [
5763
keycloak_openid_client.my_openid_client
5864
]
5965
}
6066
6167
resource "keycloak_openid_client_permissions" "my_permission" {
62-
realm_id = keycloak_realm.realm.id
63-
client_id = keycloak_openid_client.my_openid_client.id
64-
view_scope_policy_id = keycloak_openid_client_user_policy.test.id
65-
manage_scope_policy_id = keycloak_openid_client_user_policy.test.id
66-
configure_scope_policy_id = keycloak_openid_client_user_policy.test.id
67-
map_roles_scope_policy_id = keycloak_openid_client_user_policy.test.id
68-
map_roles_client_scope_scope_policy_id = keycloak_openid_client_user_policy.test.id
69-
map_roles_composite_scope_policy_id = keycloak_openid_client_user_policy.test.id
70-
token_exchange_scope_policy_id = keycloak_openid_client_user_policy.test.id
68+
realm_id = keycloak_realm.realm.id
69+
client_id = keycloak_openid_client.my_openid_client.id
70+
71+
view_scope {
72+
policies = [
73+
keycloak_openid_client_user_policy.test.id,
74+
]
75+
description = "my description"
76+
decision_strategy = "UNANIMOUS"
77+
}
7178
}
7279
```
7380

@@ -77,17 +84,29 @@ The following arguments are supported:
7784

7885
- `realm_id` - (Required) The realm this group exists in.
7986
- `client_id` - (Required) The id of the client that provides the role.
80-
- `view_scope_policy_id` - (Optional) Policy id that will be set on the scope based view permission automatically created by enabling permissions on the reference openid client.
81-
- `manage_scope_policy_id` - (Optional) Policy id that will be set on the scope based manage permission automatically created by enabling permissions on the reference openid client.
82-
- `configure_scope_policy_id` - (Optional) Policy id that will be set on the scope based configure permission automatically created by enabling permissions on the reference openid client.
83-
- `map_roles_scope_policy_id` - (Optional) Policy id that will be set on the scope based map-roles permission automatically created by enabling permissions on the reference openid client.
84-
- `map_roles_client_scope_scope_policy_id` - (Optional) Policy id that will be set on the scope based map-roles-client-scope permission automatically created by enabling permissions on the reference openid client.
85-
- `map_roles_composite_scope_policy_id` - (Optional) Policy id that will be set on the scope based map-roles-composite permission automatically created by enabling permissions on the reference openid client.
86-
- `token_exchange_scope_policy_id` - (Optional) Policy id that will be set on the scope based token-exchange permission automatically created by enabling permissions on the reference openid client.
87+
88+
#### Permission Scopes
89+
90+
Permission scopes can be defined using the following attributes:
91+
92+
- `view_scope`
93+
- `manage_scope`
94+
- `configure_scope`
95+
- `map_roles_scope`
96+
- `map_roles_client_scope_scope`
97+
- `map_roles_composite_scope`
98+
- `token_exchange_scope`
99+
100+
Each of these attributes have the following schema:
101+
102+
- `policies` - (Optional) A list of policy IDs
103+
- `description` - (Optional) A description for the permission scope
104+
- `decision_strategy` - (Optional) The decision strategy, can be one of `UNANIMOUS`, `AFFIRMATIVE`, or `CONSENSUS`.
87105

88106
### Attributes Reference
89107

90108
In addition to the arguments listed above, the following computed attributes are exported:
91109

92-
- `authorization_resource_server_id` - Resource server id representing the realm management client on which this permission is managed.
110+
- `authorization_resource_server_id` - Resource server id representing the realm management client on which this
111+
permission is managed.
93112

example/client_authorization_policys.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,16 @@ resource "keycloak_users_permissions" "my_permission" {
194194
decision_strategy = "UNANIMOUS"
195195
}
196196
}
197+
198+
resource "keycloak_openid_client_permissions" "my_permission" {
199+
realm_id = keycloak_realm.test_authorization.id
200+
client_id = keycloak_openid_client.test.id
201+
202+
view_scope {
203+
policies = [
204+
keycloak_openid_client_user_policy.test.id,
205+
]
206+
description = "my description"
207+
decision_strategy = "UNANIMOUS"
208+
}
209+
}

0 commit comments

Comments
 (0)