2016-11-29 15:30:53 +00:00
[[_service_protection_whatis_obtain_pat]]
2017-10-09 06:38:46 +00:00
= What is a PAT and How to Obtain It
2016-06-05 22:17:31 +00:00
2017-08-28 12:50:14 +00:00
A *protection API token* (PAT) is a special OAuth2 access token with a scope defined as *uma_protection*. When you create a resource server, {project_name} automatically
2016-11-15 21:34:20 +00:00
creates a role, _uma_protection_, for the corresponding client application and associates it with the client's service account.
2016-06-16 17:08:04 +00:00
2016-09-09 03:53:39 +00:00
.Service Account granted with *uma_protection* role
2017-08-28 12:50:14 +00:00
image:{project_images}/service/rs-uma-protection-role.png[alt="Service Account granted with uma_protection role"]
2016-06-05 22:17:31 +00:00
2017-08-28 12:50:14 +00:00
Resource servers can obtain a PAT from {project_name} like any other OAuth2 access token. For example, using curl:
2016-06-05 22:17:31 +00:00
```bash
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
2017-11-14 12:53:13 +00:00
-d 'grant_type=client_credentials&client_id=${client_id}&client_secret=${client_secret}' \
2016-06-05 22:17:31 +00:00
"http://localhost:8080/auth/realms/${realm_name}/protocol/openid-connect/token"
```
2016-11-15 21:34:20 +00:00
The example above is using the *client_credentials* grant type to obtain a PAT from the server. As a result, the server returns a response similar to the following:
2016-06-05 22:17:31 +00:00
```bash
{
"access_token": ${PAT},
"expires_in": 300,
"refresh_expires_in": 1800,
"refresh_token": ${refresh_token},
"token_type": "bearer",
"id_token": ${id_token},
"not-before-policy": 0,
"session_state": "ccea4a55-9aec-4024-b11c-44f6f168439e"
}
2016-11-15 21:34:20 +00:00
```
[NOTE]
2017-08-28 12:50:14 +00:00
{project_name} can authenticate your client application in different ways. For simplicity, the *client_credentials* grant type is used here,
2017-10-09 06:38:46 +00:00
which requires a _client_id_ and a _client_secret_. You can choose to use any supported authentication method.