Skip to content

Commit d46f7f3

Browse files
author
queue-it
committed
Preparing release 1.0.4
1 parent 588ab34 commit d46f7f3

File tree

7 files changed

+73
-31
lines changed

7 files changed

+73
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@queue-it/queue-token",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Ensures that end users cannot enter the queue without a valid token and to be a container which can carry sensitive user information from integrating system into the queue",
55
"repository": "https://github.com/queueit/QueueToken.V1.JavaScript",
66
"main": "dist/index.js",

src/Payload.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import {PayloadDto} from "./model/PayloadDto";
2-
import {Utils} from "./QueueITHelpers";
3-
import {TokenSerializationException} from "./Token";
4-
import {Base64} from "./helpers/Base64";
5-
import {ModeOfOperationCBC} from "./helpers/Aes";
1+
import { PayloadDto } from "./model/PayloadDto";
2+
import { Utils } from "./QueueITHelpers";
3+
import { TokenSerializationException } from "./Token";
4+
import { Base64 } from "./helpers/Base64";
5+
import { ModeOfOperationCBC } from "./helpers/Aes";
6+
import { TokenOrigin } from "./model/TokenOrigin";
67

78
export class Payload {
89
public static Enqueue(): EnqueueTokenPayloadGenerator {
@@ -33,6 +34,12 @@ export class EnqueueTokenPayloadGenerator {
3334
return this;
3435
}
3536

37+
public WithOrigin(origin: TokenOrigin): EnqueueTokenPayloadGenerator {
38+
this._payload = EnqueueTokenPayload.create(this._payload, null);
39+
this._payload.AddTokenOrigin(origin);
40+
return this;
41+
}
42+
3643
public Generate(): IEnqueueTokenPayload {
3744
return this._payload;
3845
}
@@ -42,6 +49,7 @@ export interface IEnqueueTokenPayload {
4249
readonly Key: string
4350
readonly RelativeQuality?: number
4451
readonly CustomData: Object
52+
readonly TokenOrigin: TokenOrigin
4553

4654
EncryptAndEncode(secretKey: string, tokenIdentifier: string): string
4755

@@ -52,6 +60,7 @@ export class EnqueueTokenPayload implements IEnqueueTokenPayload {
5260
private _customData: Object;
5361
private _key: string;
5462
private _relativeQuality: number
63+
private _origin: TokenOrigin
5564

5665
public get Key(): string {
5766
return this._key;
@@ -73,11 +82,16 @@ export class EnqueueTokenPayload implements IEnqueueTokenPayload {
7382
this._relativeQuality = value;
7483
}
7584

85+
public get TokenOrigin(): TokenOrigin {
86+
return this._origin;
87+
}
88+
7689
constructor() {
7790
this._customData = {};
91+
this._origin = TokenOrigin.Connector;
7892
}
7993

80-
static create(payload?: EnqueueTokenPayload, key?: string, relativeQuality?: number, customData?: object): EnqueueTokenPayload {
94+
static create(payload?: EnqueueTokenPayload, key?: string, relativeQuality?: number, customData?: object, origin?: TokenOrigin): EnqueueTokenPayload {
8195
const newPayload = new EnqueueTokenPayload();
8296
newPayload.Key = key;
8397
if (payload) {
@@ -87,13 +101,19 @@ export class EnqueueTokenPayload implements IEnqueueTokenPayload {
87101
newPayload.Key = payload.Key;
88102
}
89103
}
104+
90105
if (relativeQuality != null) {
91106
newPayload.RelativeQuality = relativeQuality
92107
}
108+
93109
if (customData) {
94110
newPayload._customData = customData;
95111
}
96112

113+
if (origin) {
114+
newPayload._origin = origin;
115+
}
116+
97117
return newPayload;
98118
}
99119

@@ -105,18 +125,24 @@ export class EnqueueTokenPayload implements IEnqueueTokenPayload {
105125
return this;
106126
}
107127

128+
public AddTokenOrigin(origin: TokenOrigin): EnqueueTokenPayload {
129+
this._origin = origin ?? TokenOrigin.Connector;
130+
return this;
131+
}
132+
108133
public Serialize(): Uint8Array {
109134
const dto = new PayloadDto();
110135
dto.Key = this.Key;
111136
dto.RelativeQuality = this.RelativeQuality;
112137
dto.CustomData = this.CustomData;
138+
dto.Origin = this.TokenOrigin;
113139

114140
return dto.Serialize();
115141
}
116142

117143
static Deserialize(input: string, secretKey: string, tokenIdentifier: string): EnqueueTokenPayload {
118144
const dto = PayloadDto.DeserializePayload(input, secretKey, tokenIdentifier);
119-
return EnqueueTokenPayload.create(null, dto.Key, dto.RelativeQuality, dto.CustomData)
145+
return EnqueueTokenPayload.create(null, dto.Key, dto.RelativeQuality, dto.CustomData, dto.Origin);
120146
}
121147

122148
EncryptAndEncode(secretKey: string, tokenIdentifier: string): string {

src/Token.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {TokenVersion} from "./model/TokenVersion";
2-
import {EnqueueTokenPayload, IEnqueueTokenPayload} from "./Payload";
3-
import {EncryptionType} from "./model/EncryptionType";
4-
import {ShaHashing, Utils} from "./QueueITHelpers";
5-
import {HeaderDto} from "./model/HeaderDto";
6-
import {Base64} from "./helpers/Base64";
1+
import { TokenVersion } from "./model/TokenVersion";
2+
import { EnqueueTokenPayload, IEnqueueTokenPayload } from "./Payload";
3+
import { EncryptionType } from "./model/EncryptionType";
4+
import { ShaHashing, Utils } from "./QueueITHelpers";
5+
import { HeaderDto } from "./model/HeaderDto";
6+
import { Base64 } from "./helpers/Base64";
77

88
const InvalidTokenExceptionMessage = "Invalid token";
99

@@ -116,13 +116,13 @@ export class EnqueueToken {
116116
}
117117

118118
public static Create(tokenIdentifier: string,
119-
customerId: string,
120-
eventId: string,
121-
issued: Date,
122-
expires: Date,
123-
ipAddress: string,
124-
xForwardedFor: string,
125-
payload: IEnqueueTokenPayload) {
119+
customerId: string,
120+
eventId: string,
121+
issued: Date,
122+
expires: Date,
123+
ipAddress: string,
124+
xForwardedFor: string,
125+
payload: IEnqueueTokenPayload) {
126126
const token = new EnqueueToken(customerId, "");
127127
token.TokenIdentifier = tokenIdentifier;
128128
token.CustomerId = customerId;

src/helpers/Aes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class Utf8Converter {
108108
}
109109

110110
// Number of rounds by keysize
111-
let numberOfRounds = {16: 10, 24: 12, 32: 14}
111+
let numberOfRounds = { 16: 10, 24: 12, 32: 14 }
112112

113113
// Round constant words
114114
let rcon = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91];

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export {Payload} from "./Payload";
2-
export {Token} from "./Token"
1+
export { Payload } from "./Payload";
2+
export { Token } from "./Token"

src/model/PayloadDto.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
import {AESEncryption, Utils} from "../QueueITHelpers";
2-
import {Base64} from "../helpers/Base64";
1+
import { AESEncryption, Utils } from "../QueueITHelpers";
2+
import { Base64 } from "../helpers/Base64";
3+
import { TokenOrigin } from "./TokenOrigin";
34

45
export class PayloadDto {
56
public RelativeQuality?: number
67
public Key: string
78
public CustomData?: object
9+
public Origin?: TokenOrigin
810

911
Serialize(): Uint8Array {
1012
const obj = {
11-
r: this.RelativeQuality,
12-
k: this.Key
13+
r: this.RelativeQuality,
14+
k: this.Key
1315
};
14-
if(this.CustomData && Object.keys(this.CustomData).length>0){
16+
17+
if (this.CustomData && Object.keys(this.CustomData).length > 0) {
1518
obj['cd'] = this.CustomData
1619
}
20+
21+
if (this.Origin) {
22+
obj['o'] = this.Origin
23+
}
24+
1725
let jsonData = JSON.stringify(obj);
1826

1927
return Utils.stringToUint8Array(jsonData);
@@ -23,14 +31,18 @@ export class PayloadDto {
2331
const headerEncrypted = Base64.decode(input);
2432
const decryptedBytes: Uint8Array = AESEncryption.DecryptPayload(secretKey, tokenIdentifier, headerEncrypted);
2533
const jsonData = JSON.parse(Utils.uint8ArrayToString(decryptedBytes));
26-
if(jsonData==null) return null;
34+
if (jsonData == null) return null;
2735

2836
const payload = new PayloadDto();
2937
payload.RelativeQuality = jsonData['r'];
3038
payload.Key = jsonData['k'];
31-
if(jsonData['cd']){
39+
40+
if (jsonData['cd']) {
3241
payload.CustomData = jsonData['cd'];
3342
}
43+
44+
jsonData['o'] = payload.Origin ?? jsonData['o'];
45+
3446
return payload;
3547
}
3648
}

src/model/TokenOrigin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum TokenOrigin {
2+
Connector,
3+
InviteOnly
4+
}

0 commit comments

Comments
 (0)