2016-11-29 15:30:53 +00:00
[[_service_protection_resources_api]]
2022-04-18 14:10:57 +00:00
= Managing resources
2016-06-05 22:17:31 +00:00
Resource servers can manage their resources remotely using a UMA-compliant endpoint.
2022-02-08 13:07:16 +00:00
[source,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set
----
2016-06-05 22:17:31 +00:00
2018-02-28 07:53:43 +00:00
This endpoint provides operations outlined as follows (entire path omitted for clarity):
2016-06-05 22:17:31 +00:00
* Create resource set description: POST /resource_set
* Read resource set description: GET /resource_set/{_id}
* Update resource set description: PUT /resource_set/{_id}
* Delete resource set description: DELETE /resource_set/{_id}
* List resource set descriptions: GET /resource_set
2018-02-28 07:53:43 +00:00
For more information about the contract for each of these operations, see https://docs.kantarainitiative.org/uma/wg/oauth-uma-federated-authz-2.0-09.html#reg-api[UMA Resource Registration API].
2018-06-22 19:03:46 +00:00
2022-04-18 14:10:57 +00:00
== Creating a resource
2018-06-22 19:03:46 +00:00
To create a resource you must send an HTTP POST request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
2018-06-22 19:03:46 +00:00
curl -v -X POST \
2022-02-08 13:07:16 +00:00
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set \
2018-06-22 19:03:46 +00:00
-H 'Authorization: Bearer '$pat \
-H 'Content-Type: application/json' \
-d '{
"name":"Tweedl Social Service",
"type":"http://www.example.com/rsrcs/socialstream/140-compatible",
"icon_uri":"http://www.example.com/icons/sharesocial.png",
"resource_scopes":[
"read-public",
"post-updates",
"read-private",
"http://www.example.com/scopes/all"
]
}'
2022-02-08 13:07:16 +00:00
----
2018-06-22 19:03:46 +00:00
2022-10-19 06:33:25 +00:00
By default, the owner of a resource is the resource server. If you want to define a different owner, such as a
2018-06-22 19:03:46 +00:00
specific user, you can send a request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
2018-06-22 19:03:46 +00:00
curl -v -X POST \
2022-02-08 13:07:16 +00:00
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set \
2018-06-22 19:03:46 +00:00
-H 'Authorization: Bearer '$pat \
-H 'Content-Type: application/json' \
-d '{
"name":"Alice Resource",
"owner": "alice"
}'
2022-02-08 13:07:16 +00:00
----
2018-06-22 19:03:46 +00:00
Where the property `owner` can be set with the username or the identifier of the user.
2022-04-18 14:10:57 +00:00
== Creating user-managed resources
2018-06-22 19:03:46 +00:00
2022-07-26 13:30:45 +00:00
By default, resources created via Protection API can not be managed by resource owners through the <<_service_authorization_my_resources, Account Console>>.
2018-06-22 19:03:46 +00:00
To create resources and allow resource owners to manage these resources, you must set `ownerManagedAccess` property as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
2018-06-22 19:03:46 +00:00
curl -v -X POST \
2022-02-08 13:07:16 +00:00
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set \
2018-06-22 19:03:46 +00:00
-H 'Authorization: Bearer '$pat \
-H 'Content-Type: application/json' \
-d '{
"name":"Alice Resource",
"owner": "alice",
"ownerManagedAccess": true
}'
2022-02-08 13:07:16 +00:00
----
2018-06-22 19:03:46 +00:00
2022-04-18 14:10:57 +00:00
== Updating resources
2018-06-22 19:03:46 +00:00
To update an existing resource, send an HTTP PUT request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
2018-06-22 19:03:46 +00:00
curl -v -X PUT \
2022-02-08 13:07:16 +00:00
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set/{resource_id} \
2018-06-22 19:03:46 +00:00
-H 'Authorization: Bearer '$pat \
-H 'Content-Type: application/json' \
-d '{
"_id": "Alice Resource",
"name":"Alice Resource",
"resource_scopes": [
"read"
]
}'
2022-02-08 13:07:16 +00:00
----
2018-06-22 19:03:46 +00:00
2022-04-18 14:10:57 +00:00
== Deleting resources
2018-06-22 19:03:46 +00:00
To delete an existing resource, send an HTTP DELETE request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
2018-06-22 19:03:46 +00:00
curl -v -X DELETE \
2022-02-08 13:07:16 +00:00
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set/{resource_id} \
2018-06-22 19:03:46 +00:00
-H 'Authorization: Bearer '$pat
2022-02-08 13:07:16 +00:00
----
2018-06-22 19:03:46 +00:00
2022-04-18 14:10:57 +00:00
== Querying resources
2018-06-22 19:03:46 +00:00
To query the resources by `id`, send an HTTP GET request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set/{resource_id}
----
2018-06-22 19:03:46 +00:00
To query resources given a `name`, send an HTTP GET request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set?name=Alice Resource
----
2018-06-22 19:03:46 +00:00
2020-09-21 18:45:51 +00:00
By default, the `name` filter will match any resource with the given pattern. To restrict the query to only return resources with an exact match, use:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set?name=Alice Resource&exactName=true
----
2020-09-21 18:45:51 +00:00
2018-06-22 19:03:46 +00:00
To query resources given an `uri`, send an HTTP GET request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set?uri=/api/alice
----
2018-06-22 19:03:46 +00:00
To query resources given an `owner`, send an HTTP GET request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set?owner=alice
----
2018-06-22 19:03:46 +00:00
To query resources given an `type`, send an HTTP GET request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set?type=albums
----
2018-06-22 19:03:46 +00:00
To query resources given an `scope`, send an HTTP GET request as follows:
2022-02-08 13:07:16 +00:00
[source,bash,subs="attributes+"]
----
http://${host}:${port}{kc_realms_path}/${realm_name}/authz/protection/resource_set?scope=read
----
2018-06-22 19:03:46 +00:00
When querying the server for permissions use parameters `first` and `max` results to limit the result.