Personal access token
Personal access tokens (PATs) provide a secure way for users to grant access tokens without using their credentials and interactive sign-in. This is useful for CI/CD, scripts, or applications that need to access resources programmatically.
Managing personal access tokensโ
Using Consoleโ
You can manage personal access tokens in the User Details page of the Console. In the card "Authentication", you can see the list of personal access tokens and create new ones.
Using Management APIโ
After setting up the Management API, you can use the API endpoints to create, list, and delete personal access tokens.
Use PATs to grant access tokensโ
After creating a PAT, you can use it to grant access tokens to your application by using the token exchange endpoint.
Requestโ
The application makes a token exchange request to the tenant's token endpoint with a special grant type using the HTTP POST method. The following parameters are included in the HTTP request entity-body using the application/x-www-form-urlencoded
format.
client_id
: REQUIRED. The client ID of the application.grant_type
: REQUIRED. The value of this parameter must beurn:ietf:params:oauth:grant-type:token-exchange
indicates that a token exchange is being performed.resource
: OPTIONAL. The resource indicator, the same as other token requests.scope
: OPTIONAL. The requested scopes, the same as other token requests.subject_token
: REQUIRED. The user's PAT.subject_token_type
: REQUIRED. The type of the security token provided in thesubject_token
parameter. The value of this parameter must beurn:logto:token-type:personal_access_token
.
Responseโ
If the token exchange request is successful, the tenant's token endpoint returns an access token that represents the identity of the user. The response includes the following parameters in the HTTP response entity-body using the application/json
format.
access_token
: REQUIRED. The access token of the user, which is the same as other token requests likeauthorization_code
orrefresh_token
.issued_token_type
: REQUIRED. The type of the issued token. The value of this parameter must beurn:ietf:params:oauth:token-type:access_token
.token_type
: REQUIRED. The type of the token. The value of this parameter must beBearer
.expires_in
: REQUIRED. The lifetime in seconds of the access token.scope
: OPTIONAL. The scopes of the access token.
Example token exchangeโ
POST /oidc/token HTTP/1.1
Host: tenant.logto.app
Content-Type: application/x-www-form-urlencoded
Authorization: Basic <base64(client-id:client-secret)>
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange
&scope=profile
&subject_token=pat_W51arOqe7nynW75nWhvYogyc
&subject_token_type=urn%3Alogto%3Atoken-type%3Apersonal_access_token
HTTP/1.1 200 OK
Content-Type: application/json
{
"access_token": "eyJhbGci...zg",
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "profile"
}
The example access token payload:
{
"jti": "iFtbZBeh2M1cTTBuKbHk4",
"sub": "123",
"iss": "https://tenant.logto.app/oidc",
"exp": 1672531200,
"iat": 1672527600,
"scope": "profile",
"client_id": "client-id"
}