> 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
