Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-5171][RTN22] Server initiated auth/ renew token #56

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/AblyBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public function __construct(AblyRest $ably, $config)
}

/**
* @return int
* Get the current server time adjusted by the Ably server time difference (if clock difference exists).
*
* @return int The current server time in seconds.
*/
private function getServerTime()
{
Expand Down Expand Up @@ -217,6 +219,14 @@ public function getSignedToken($channelName, $token, $clientId, $guardedChannelC
$iat = $payload['iat'];
$exp = $payload['exp'];
$channelClaims = json_decode($payload['x-ably-capability'], true);
sacOO7 marked this conversation as resolved.
Show resolved Hide resolved

// Check if the token is about to expire and renew it if necessary
// The Laravel Echo client typically initiates token renewal 30 seconds before expiry
// Spec: RTN22
if ($exp - $serverTimeFn() <= 30) {
$iat = $serverTimeFn();
$exp = $iat + $this->tokenExpiry;
}
} else {
$iat = $serverTimeFn();
$exp = $iat + $this->tokenExpiry;
Expand Down
Loading