For AI agents: this page in Markdown: https://www.pubnub.com/docs/security/access-control/update-expired-token.md. Documentation index: https://www.pubnub.com/llms-full.txt.
Update an expired token
A request that uses an expired token fails with 403 Token is expired. The request is not retried automatically. You must set a new token, reconnect, and retry.
Before you start
Confirm you have:
- A server endpoint that grants new tokens on request. See Grant, change, and revoke permissions.
- A client initialized with an
authKey. See Initialize a client SDK with an auth key.
Steps
- Detect the
403 Token is expiredresponse on the client. - Request a new token from your server.
- Set the new token on the client using
setToken. See Initialize a client SDK with an auth key for the call in your SDK. - Call
reconnect()on the PubNub client. The method name may vary across SDKs. - Retry the failed request.
Reconnect is required
Setting a new token alone is not enough. The client must call reconnect() after setting the token, or subsequent requests may still fail.
Related pages
- Change or extend access. Proactive strategies for refreshing tokens before they expire.
- Initialize a client SDK with an auth key.
setTokenreference and initialization code. - Grant, change, and revoke permissions. Issue a new token from your server.