Open farshidtz opened 4 years ago
In Keycloak, scopes can be associated with roles and users in the following way:
In the OAuth2 token request, when asking for the specific scope, the server will provide it in response only if the user has an associated role.
E.g. password grant:
curl --location --request POST '<token-endpoint>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=test-client' \
--data-urlencode 'username=tester' \
--data-urlencode 'password=******' \
--data-urlencode 'scope=limited'
{
"access_token": "<access-token>",
"expires_in": 300,
...
"scope": "email limited profile"
}
Access Token Payload:
{
"exp": 1592929675,
"iat": 1592929375,
"typ": "Bearer",
...
"scope": "email limited profile",
}
Currently, the Keycloak plugin which uses the OpenID Connect protocol performs access control on endpoint/methods using user claims (username, group) or the clientID.
We may be able to use OAuth2 scopes for the same level of access control.
OAuth2 security scheme: https://www.w3.org/TR/wot-thing-description/#oauth2securityscheme
Example: https://www.w3.org/TR/wot-thing-description/#example-15
From OAuth2 specs:
Or a more understandable version:
There are also a few examples here.