Authenticating with a Personal Access Token
Authenticating with a Personal Access Token
You can use API Mediation Layer to generate, validate, and invalidate a Personal Access Token (PAT) that can enable access to tools such as VCS without having to use credentials of a specific person. The use of PAT does not require storing mainframe credentials as part of the automation configuration on a server during application development on z/OS. Additionally, using a PAT makes it possible to limit access to specific services and users by means of token revocation when using a token.
Gateway APIs are available to both users as well as security administrators. APIs for users can accomplish the following functions:
APIs for security administrators are protected by SAF resource checking and can accomplish the following functions:
- Invalidate all tokens for a user
- Invalidate all tokens for a service
- Evict non-relevant tokens and rules
An SMF record can be issued when a Personal Access Token is generated. For more information, see SMF records issued by API ML
For detailed information about using the Personal Access Token as part of single sign on, see the section Using the Personal Access Token to authenticate later in this article.
For additional information, see the Medium blog post Personal Access Tokens for the Zowe API Mediation Layer.
User APIs
Generate a token
A user can create the Personal Access Token by calling the following REST API endpoint through the Gateway:
POST /auth/access-token/generate
The full path of the /auth/access-token/generate
endpoint appears as:
https://{gatewayUrl}:{gatewayPort}/gateway/api/v1/auth/access-token/generate
.
The request requires the body in the following format:
{
"validity": 90,
"scopes": ["<serviceId_1>,<serviceId_2>"]
}
-
validity
Specifies the expiration time of the token. The maximum threshold is 90 days. -
scopes
Specifies the access limits on a service level. This parameter introduces a higher level of security in some aspects. Users are required to provide a scope. If no service is specified, it is not possible to authenticate using the token.
When creation is successful, the response to the request is a body containing the PAT with a status code of 200
. When creation fails, the user receives a status code of 401
.
Validate a token
The user can validate the Personal Access Token by calling the following REST API endpoint through the Gateway:
POST /auth/access-token/validate
The full path of the /auth/access-token/validate
endpoint appears as https://{gatewayUrl}:{gatewayPort}/gateway/api/v1/auth/access-token/validate
.
The request requires the body in the following format:
{
"token": "<token>",
"serviceId": "<serviceId>"
}
The user has the option of calling this API to validate the token, however, validation is also automatically performed by the API ML.
When validation is successful, the response to the request is an empty body with a status code of 200
. When validation fails, the user receives a status code of 401
.
Invalidate a specific token
The user can invalidate the Personal Access Token by calling the following REST API endpoint through the Gateway:
DELETE /auth/access-token/revoke
The full path of the /auth/access-token/revoke
endpoint appears as https://{gatewayUrl}:{gatewayPort}/gateway/api/v1/auth/access-token/revoke
.
The request requires the body in the following format:
{
"token": "<token_value>"
}
When the /auth/access-token/revoke
endpoint is called, the provided hash of the PAT is stored in the cache by the Caching Service under the invalidTokens
key. As such, the token is invalidated.
Access to these entries is protected by the API ML client certificate.
When invalidation is successful, the response to the request is an empty body with a status code of 200
. When invalidation fails, the user receives a status code of 401
.