Skip to content

Commit 9800841

Browse files
author
Jim Rouse
committed
Initial Commit
1 parent 96ad13f commit 9800841

1,735 files changed

Lines changed: 149043 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/nbproject/private/
2+
Tests/vendor
3+
Tests/composer.lock
4+
/simpletest
5+
/.vs

README.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,94 @@
1-
# QueueToken.V1.PHP
1+
[![npm](https://img.shields.io/npm/v/@queue-it/queue-token)](https://www.npmjs.com/package/@queue-it/queue-token)
2+
3+
# Queue-it Queue Token SDK for PHP
4+
5+
The Queue-it Queue Token SDK is used to ensure 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.
6+
7+
## The Token
8+
9+
The token consists of two parts. Firstly, a header containing non-sensitive metadata. Secondly the payload of the token.
10+
Both header and payload are in JSON format.
11+
12+
### Token Header
13+
14+
```json
15+
{
16+
"typ": "QT1",
17+
"enc": "AES256",
18+
"iss": 1526464517,
19+
"exp": 1526524517,
20+
"ti": "159aba3e-55e1-4f54-b6ee-e5b943d7e885",
21+
"c": "ticketania",
22+
"e": "demoevent",
23+
"ip": "75.86.129.4",
24+
"xff": "45.67.2.4,34.56.3.2"
25+
}
26+
```
27+
28+
- `typ`: The type of the token. Value must be "QT1". Required.
29+
- `enc`: Payload encryption algorithm. Value must be "AES256". Required.
30+
- `iss`: NumericDate of when token was issued. Required.
31+
- `exp`: NumericDate of when token expires. Optional.
32+
- `ti`: Unique Token ID (e.g. uuid). Used to uniquely identify tokens and restrict replay attacks. Required.
33+
- `c`: The Customer ID of the issuer. Token will only be valid on events on this account. Required.
34+
- `e`: The Event ID. If provided, token will only be valid on this event. Optional.
35+
- `ip`: The IP address of user the token is issued for. If provided, the IP address in the token is validated against the client IP before issuing a new Queue id. Optional.
36+
- `xff`: The X-Forwarded-For header of the request when the token is issued. Only used for logging. Optional.
37+
38+
### Token Payload
39+
40+
```json
41+
{
42+
"r": 0.4578,
43+
"k": "XKDI42W",
44+
"cd": { "size": "medium" }
45+
}
46+
```
47+
48+
- `r`: The relative quality of the key. Must be a decimal value. Used for determining the quality of the token. Optional
49+
- `k`: A unique key that holds value to the integrating system (e.g. email or user id). Used to restrict users from issuing multiple queue ids. Optional.
50+
- `cd`: Any custom data of the user. This is a set of key-value pairs. Optional
51+
52+
## Usage
53+
54+
```javascript
55+
const secretKey = '...';
56+
const token = Token
57+
.Enqueue("ticketania")
58+
.WithPayload(Payload
59+
.Enqueue()
60+
.WithKey("XKDI42W")
61+
.WithRelativeQuality(0.4578)
62+
.WithCustomData("size", "medium")
63+
.Generate())
64+
.WithEventId("demoevent")
65+
.WithIpAddress("75.86.129.4", "45.67.2.4,34.56.3.2")
66+
.WithValidity(60000)
67+
.Generate(secretKey);
68+
69+
const tokenValue = token.Token;
70+
```
71+
72+
### Specifying token identifier prefix
73+
74+
A prefix for the token identifier can optionally be provided to restrict the user session after getting through the queue to the one used before entering the queue. Once the user is through the queue the token identifier is provided to the target application in the Known User token. The format of the token identifier is then `[YOUR PREFIX]~[GUID]`, e.g: AnfTDnpwazllYmnmgaCJ8tErV80YHv77ni5NgqQNhfWwxNqrNcHb~e937ef0d-48ec-4ff7-866e-52033273cb3d.
75+
76+
```javascript
77+
const tokenIdentifierPrefix = "AnfTDnpwazllYmnmgaCJ8tErV80YHv77ni5NgqQNhfWwxNqrNcHb";
78+
const token = Token
79+
.Enqueue("ticketania", tokenIdentifierPrefix)
80+
.Generate(secretKey);
81+
82+
const tokenIdentifier = token.TokenIdentifier;
83+
// tokenIdentifier example: AnfTDnpwazllYmnmgaCJ8tErV80YHv77ni5NgqQNhfWwxNqrNcHb~e937ef0d-48ec-4ff7-866e-52033273cb3d
84+
```
85+
86+
## Serialized Token
87+
88+
> eyJ0eXAiOiJRVDEiLCJlbmMiOiJBRVMyNTYiLCJpc3MiOjE1MzQ3MjMyMDAwMDAsImV4cCI6MTUzOTEyOTYwMDAwMCwidGkiOiJhMjFkNDIzYS00M2ZkLTQ4MjEtODRmYS00MzkwZjZhMmZkM2UiLCJjIjoidGlja2V0YW5pYSIsImUiOiJteWV2ZW50In0.0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZc_CQdD63hJre3Sedu0-9zIs.aZgzkJm57etFaXjjME_-9LjOgPNTTqkp1aJ057HuEiU
89+
90+
The format of the token is [header].[payload].[hash] where each part is Base64Url encoded.
91+
The payload is AES 256 encrypted with the secret key supplied in the `.Generate(secretKey)` method.
92+
If the "e" key is provided in the header, the secret key on the event must be used.
93+
If no "e" key is provided the default key on the customer account must be used.
94+
The token is signed with SHA 256 using the same secret key.

composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"require-dev": {
3+
"phpunit/phpunit": "^11.4"
4+
},
5+
"autoload": {
6+
"psr-4": {
7+
"QueueIT\\": "src/"
8+
}
9+
},
10+
"require": {
11+
"ext-json": "*",
12+
"ext-openssl": "*"
13+
}
14+
}

0 commit comments

Comments
 (0)