> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtrefresh.md).

# JWTRefresh

Verifies an existing JWT and re-issues it with fresh `iat`, `jti`, and optionally a new `exp`. All application claims (`sub`, `iss`, `aud`, custom claims) are preserved.

## Method Signature

```
JWTRefresh( token, [key], [algorithm], [options] )
```

### Arguments

| Argument    | Type     | Required | Description                                                      | Default |
| ----------- | -------- | -------- | ---------------------------------------------------------------- | ------- |
| `token`     | `string` | Yes      | Existing compact JWS token to refresh.                           |         |
| `key`       | `any`    | No       | Signing/verification key. Optional when defaults are configured. | `null`  |
| `algorithm` | `string` | No       | Algorithm to use for the new token.                              | `null`  |
| `options`   | `struct` | No       | See options table below.                                         | `{}`    |

#### Options

| Option         | Type      | Description                                                                 | Default |
| -------------- | --------- | --------------------------------------------------------------------------- | ------- |
| `allowExpired` | `boolean` | Allow refreshing an expired token. The signature is still verified.         | `false` |
| `expireIn`     | `numeric` | Seconds until the refreshed token expires.                                  | `null`  |
| `headers`      | `struct`  | JOSE headers to include in the new token (overrides originals).             | `{}`    |
| `claims`       | `struct`  | Optional claim assertions to enforce during verification before refreshing. | `{}`    |

### Returns

A new compact JWS string with refreshed time claims.

## Examples

```javascript
// Standard refresh — token must still be valid
newToken = jwtRefresh( oldToken, secret, "HS256" );

// Refresh with a new 1-hour expiration
newToken = jwtRefresh( oldToken, secret, "HS256", { expireIn: 3600 } );

// Allow refreshing an expired token (grace period)
newToken = jwtRefresh( oldToken, secret, "HS256", {
    allowExpired : true,
    expireIn     : 3600
} );
```

## Related

* [JWTVerify()](/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtverify.md)
* [JWTCreate()](/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtcreate.md)
* [Signing (JWS) Guide](/boxlang-framework/modularity/jwt/signing-jws.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtrefresh.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
