Skip to content

Commit 60f0134

Browse files
committed
Initial commit
0 parents  commit 60f0134

28 files changed

+7318
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
6+
[*.js]
7+
insert_final_newline=false
8+
9+
[*.md]
10+
insert_final_newline=false
11+
12+
[package.json]
13+
indent_style = space
14+
indent_size = 2
15+
insert_final_newline=false

.eslintrc.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"plugin:compat/recommended",
8+
"plugin:sonarjs/recommended"
9+
],
10+
"parser": "@typescript-eslint/parser",
11+
"parserOptions": {
12+
"ecmaVersion": 2016
13+
},
14+
"plugins": [
15+
"@typescript-eslint",
16+
"sonarjs"
17+
],
18+
"rules": {
19+
"no-multiple-empty-lines": "error",
20+
"no-console": "error",
21+
"no-empty": "error",
22+
"no-irregular-whitespace": "error",
23+
"no-unused-vars": "off",
24+
"no-alert": "error",
25+
"no-unreachable": "error",
26+
"sonarjs/cognitive-complexity": "warn",
27+
"sonarjs/no-small-switch": "warn",
28+
"sonarjs/no-identical-functions": "warn",
29+
"sonarjs/prefer-while": "off"
30+
},
31+
"settings": {
32+
"polyfills": [
33+
"Promise",
34+
"fetch"
35+
]
36+
}
37+
}

.gitignore

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
11+
# Diagnostic reports (https://nodejs.org/api/report.html)
12+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
*.lcov
26+
27+
# nyc test coverage
28+
.nyc_output
29+
30+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
31+
.grunt
32+
33+
# Bower dependency directory (https://bower.io/)
34+
bower_components
35+
36+
# node-waf configuration
37+
.lock-wscript
38+
39+
# Compiled binary addons (https://nodejs.org/api/addons.html)
40+
build/Release
41+
42+
# Dependency directories
43+
node_modules/
44+
jspm_packages/
45+
46+
# Snowpack dependency directory (https://snowpack.dev/)
47+
web_modules/
48+
49+
# TypeScript cache
50+
*.tsbuildinfo
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Microbundle cache
59+
.rpt2_cache/
60+
.rts2_cache_cjs/
61+
.rts2_cache_es/
62+
.rts2_cache_umd/
63+
64+
# Optional REPL history
65+
.node_repl_history
66+
67+
# Output of 'npm pack'
68+
*.tgz
69+
70+
# Yarn Integrity file
71+
.yarn-integrity
72+
73+
# dotenv environment variables file
74+
.env
75+
.env.test
76+
77+
# parcel-bundler cache (https://parceljs.org/)
78+
.cache
79+
.parcel-cache
80+
81+
# Next.js build output
82+
.next
83+
84+
# Nuxt.js build / generate output
85+
.nuxt
86+
dist
87+
88+
# Gatsby files
89+
.cache/
90+
# Comment in the public line in if your project uses Gatsby and not Next.js
91+
# https://nextjs.org/blog/next-9-1#public-directory-support
92+
# public
93+
94+
# vuepress build output
95+
.vuepress/dist
96+
97+
# Serverless directories
98+
.serverless/
99+
100+
# FuseBox cache
101+
.fusebox/
102+
103+
# DynamoDB Local files
104+
.dynamodb/
105+
106+
# TernJS port file
107+
.tern-port
108+
109+
# Stores VSCode versions used for testing VSCode extensions
110+
.vscode-test
111+
112+
# yarn v2
113+
114+
.yarn/cache
115+
.yarn/unplugged
116+
.yarn/build-state.yml
117+
.pnp.*
118+
119+
*.iml
120+
.idea
121+
/.vs
122+
/.vscode
123+
/pipelines

.husky/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm test
5+
lint-staged

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Queue-it
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

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

0 commit comments

Comments
 (0)