Skip to content

Commit e285da0

Browse files
committed
Fixed issue with JWT token not having an expiry on the server initially when set from the server-side
1 parent 11bb17b commit e285da0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"async": "2.0.0",
1212
"base64id": "0.1.0",
1313
"lodash.clonedeep": "4.5.0",
14-
"sc-auth": "~3.3.0",
14+
"sc-auth": "~4.0.0",
1515
"sc-domain": "~1.0.1",
1616
"sc-emitter": "~1.1.0",
1717
"sc-errors": "~1.2.0",

scsocket.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ SCSocket.prototype.emit = function (event, data, callback, options) {
307307
SCSocket.prototype.setAuthToken = function (data, options, callback) {
308308
var self = this;
309309

310-
this.authToken = data;
310+
var authToken = cloneDeep(data);
311311
this.authState = this.AUTHENTICATED;
312312

313313
if (options == null) {
@@ -321,9 +321,11 @@ SCSocket.prototype.setAuthToken = function (data, options, callback) {
321321
}
322322
}
323323

324+
options.mutatePayload = true;
325+
324326
var defaultSignatureOptions = this.server.defaultSignatureOptions;
325327

326-
if (data && data.exp == null) {
328+
if (authToken && authToken.exp == null) {
327329
options.expiresIn = defaultSignatureOptions.expiresIn;
328330
}
329331
if (defaultSignatureOptions.algorithm != null) {
@@ -333,7 +335,7 @@ SCSocket.prototype.setAuthToken = function (data, options, callback) {
333335
options.async = defaultSignatureOptions.async;
334336
}
335337

336-
this.server.auth.signToken(data, this.server.signatureKey, options, function (err, signedToken) {
338+
this.server.auth.signToken(authToken, this.server.signatureKey, options, function (err, signedToken) {
337339
if (err) {
338340
self._onSCClose(4002, err);
339341
self.socket.close(4002);
@@ -345,6 +347,8 @@ SCSocket.prototype.setAuthToken = function (data, options, callback) {
345347
self.emit('#setAuthToken', tokenData, callback);
346348
}
347349
});
350+
351+
this.authToken = authToken;
348352
};
349353

350354
SCSocket.prototype.getAuthToken = function () {

0 commit comments

Comments
 (0)