This import creates a new resource-indicators
realm with a photoz
client.
The photoz client defines available resource-indicators via the authorization-services resources.
Create a user tester
with password test
in the resource-indicators
realm.
Then you should be able to execute the following requests via curl.
Note the resource
parameter which enables the client to select which resources should be associated with the authorization.
KC_ISSUER="http://localhost:8081/auth/realms/resource-indicators"
KC_CLIENT_ID=photoz
KC_CLIENT_SECRET=I5TkulMR7zW0rjXY0hTLSoPnyc9kgVrr
KC_USERNAME="tester"
KC_PASSWORD="test"
# Obtain Token via grant_type=password
KC_AT_RESPONSE=$(curl -v \
-d "grant_type=password" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "username=$KC_USERNAME" \
-d "password=$KC_PASSWORD" \
-d "resource=https://api.acme.com/galleries" \
-d "resource=https://api.acme.com/photos" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_AT_RESPONSE"
KC_REFRESH_TOKEN=$(echo $KC_AT_RESPONSE | jq -r ".refresh_token")
echo "$KC_REFRESH_TOKEN"
# Obtain Token via grant_type=password V2
KC_AT_RESPONSE=$(curl -v \
-d "grant_type=password" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "username=$KC_USERNAME" \
-d "password=$KC_PASSWORD" \
-d "resource=https://api.acme.com/galleries" \
-d "resource=https://api.acme.com/photos" \
-d "resource=https://api.acme.com/accounts" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_AT_RESPONSE"
KC_REFRESH_TOKEN=$(echo $KC_AT_RESPONSE | jq -r ".refresh_token")
echo "$KC_REFRESH_TOKEN"
# Refresh Token with photos resource
KC_RT_RESPONSE=$(curl -v \
-d "grant_type=refresh_token" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "refresh_token=$KC_REFRESH_TOKEN" \
-d "resource=https://api.acme.com/photos" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_RT_RESPONSE"
# Refresh Token with galleries resource
KC_RT_RESPONSE=$(curl -v \
-d "grant_type=refresh_token" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "refresh_token=$KC_REFRESH_TOKEN" \
-d "resource=https://api.acme.com/galleries" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_RT_RESPONSE"
# Refresh Token with invalid resource
KC_RT_RESPONSE=$(curl -v \
-d "grant_type=refresh_token" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "refresh_token=$KC_REFRESH_TOKEN" \
-d "resource=https://api.acme.com/invalid" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_RT_RESPONSE"
# Refresh Token without resources
KC_RT_RESPONSE=$(curl -v \
-d "grant_type=refresh_token" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "refresh_token=$KC_REFRESH_TOKEN" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_RT_RESPONSE"
# Refresh Token with new not initially requested resource
KC_RT_RESPONSE=$(curl -v \
-d "grant_type=refresh_token" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "refresh_token=$KC_REFRESH_TOKEN" \
-d "resource=https://api.acme.com/accounts" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_RT_RESPONSE"
---
# Obtain Token via grant_type=client_credentials
KC_AT_RESPONSE=$(curl -v \
-d "grant_type=client_credentials" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "resource=https://api.acme.com/galleries" \
-d "resource=https://api.acme.com/photos" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_AT_RESPONSE"
# Obtain Token with resource https://api.acme.com/galleries
KC_AT_RESPONSE=$(curl -v \
-d "grant_type=client_credentials" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "resource=https://api.acme.com/galleries" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_AT_RESPONSE"
# Obtain Token with resource https://api.acme.com/photos
KC_AT_RESPONSE=$(curl -v \
-d "grant_type=client_credentials" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "resource=https://api.acme.com/photos" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_AT_RESPONSE"
# Attempt to obtain Token with resource https://api.acme.com/invalid
KC_AT_RESPONSE=$(curl -v \
-d "grant_type=client_credentials" \
-d "client_id=$KC_CLIENT_ID" \
-d "client_secret=$KC_CLIENT_SECRET" \
-d "resource=https://api.acme.com/invalid" \
$KC_ISSUER/protocol/openid-connect/token)
echo "$KC_AT_RESPONSE"