# Applying Refresh Token

After user authentication is completed, both the access token and refresh token will be returned. When the access token expires, you can use the refresh token to obtain a new access token.

Example request:

```
curl -v -X POST https://{digiRunner_DOMAIN}/oauth/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Authorization: Basic {client_secret}' \
-d 'grant_type=refresh_token' \
-d 'refresh_token={refresh_token}'
```

Parameters with details:

<table><thead><tr><th width="185">Parameter</th><th width="81">Type</th><th width="129">Requirement</th><th>Description</th></tr></thead><tbody><tr><td><code>client_secret</code></td><td>String</td><td>Required</td><td><p><strong>Scenario I. Higher-Security (Client Password Required)</strong></p><p>1. Client Password registered with digiRunner; needs to be encoded with Base64</p><p></p><p>2. Concatenate the client ID with ":" and the encoded client password, then encode the result with Base64 again to generate the value to be used</p><p></p><p>3. Example:</p><p>Client ID: tspclient</p><p>Client Password: tsp123abcd</p><p></p><p>Formula for generating the value:</p><p>Base64 Encode(ClientID+":"+Base64 Encode(Client Password))</p><p>Base64 Encode(tspclient+":"+Base64 Encode(tsp123abcd))</p><p>Base64 Encode(tspclient:dHNwMTIzYWJjZA==)</p><p></p><p>Output for client_secret:</p><p>dHNwY2xpZW50OmRITndNVEl6WVdKalpBPT0=</p><p> </p><p><strong>Scenario II. PKCE + Public Client (Client Password Not Required)</strong></p><p>When the <strong>Public Client (With PKCE)</strong> option is selected in digiRunner's <strong>OAuth grant type</strong>, the client password is not required.</p><p></p><p>1. Concatenate the client ID with ":" (no client password is required)</p><p></p><p>2. Example:</p><p>Client ID: tspclient</p><p>Client Password: ""</p><p></p><p>Formula for generating the value:</p><p>Base64 Encode(ClientID+":")</p><p>Base64 Encode(tspclient+":")</p><p>Base64 Encode(tspclient:)</p><p></p><p>Output for client_secret:</p><p>dHNwY2xpZW50Og==</p></td></tr><tr><td><code>grant_type</code></td><td>String</td><td>Required</td><td><code>refresh_token</code>, a fixed value</td></tr><tr><td><code>refresh_token</code></td><td>String</td><td>Required</td><td><p>Refresh Token, associated with the access token that requires refreshing</p><p>If the refresh token has expired, you must prompt the user to log in again to generate a new access token.</p></td></tr></tbody></table>

### Example of Successful Response

If the refresh is successful, a new access token will be returned.

Example:

```
{
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJub2RlIjoiZXhlY3V0b3IxIiwiYXVkIjpbIllXUnRhVzVCVUVrIl0sInVzZXJfbmFtZSI6InRzcHVzZXIiLCJvcmdfaWQiOiIxMDAwMDAiLCJzY29wZSI6WyIyMDAwMDAwMDA2Il0sInN0aW1lIjoxNjg0ODA5NzE3NjY4LCJleHAi...",
    "expires_in": 86399,
    "jti": "41fa8a7b-b21d-4598-b254-5ffbed8b619f",
    "node": "executor1",
    "org_id": "100000",
    "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJub2RlIjoiZXhlY3V0b3IxIiwiYXVkIjpbIllXUnRhVzVCVUVrIl0sInVzZXJfbmFtZSI6InRzcHVzZXIiLCJvcmdfaWQiOiIxMDAwMDAiLCJzY29wZSI6WyIyMDAwMDAwMDA2Il0sImF0aSI6ImMyYzAzNTc0LTI2ODItNGYwMi...",
    "scope": "2000000006",
    "stime": 1684742522981,
    "token_type": "bearer"
}
```

### Example of Error Response

If the refresh token has expired, a 401 Unauthorized HTTP status code and JSON response will be returned.

Example:

```
{
    "error": "invalid_token",
    "error_description": "Invalid refresh token (expired): eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJub2RlIjoiZXhlY3V0b3IxIiwiYXVkIjpbIllXUnRhVzVCVUVrIl0sInVzZXJfbmFtZSI6InRzcHVzZXIiLCJvcmdfaWQiOiIxMDAwMDAiLCJzY29wZSI6WyIyMDAwMDAwMDA2Il0sImF0aSI6ImMyYzAzNTc0LTI2ODItNGYwMi..."
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tpi.dev/api-integration-guide/token-lifecycle-management-mechanism/applying-refresh-token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
