@nsshunt/stsoauth2plugin 0.1.38 → 0.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +27 -0
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/npm-publish.yml +54 -0
- package/babel.config.json +6 -0
- package/build.sh +29 -0
- package/dist/Utils/CryptoUtils.js +32 -0
- package/dist/Utils/CryptoUtils.js.map +1 -0
- package/dist/Utils/QueryParams.js +49 -0
- package/dist/Utils/QueryParams.js.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.js +8 -0
- package/dist/index.test.js.map +1 -0
- package/dist/stsStorage.js +152 -0
- package/dist/stsStorage.js.map +1 -0
- package/dist/stsoauth2manager.js +354 -0
- package/dist/stsoauth2manager.js.map +1 -0
- package/dist/stsoauth2types.js +31 -0
- package/dist/stsoauth2types.js.map +1 -0
- package/dist/stsoauth2worker.js +587 -0
- package/dist/stsoauth2worker.js.map +1 -0
- package/package-vite.json +58 -0
- package/package.json +4 -13
- package/src/Utils/CryptoUtils.ts +32 -0
- package/src/Utils/QueryParams.ts +48 -0
- package/src/index.test.ts +10 -0
- package/src/index.ts +12 -0
- package/src/stsStorage.ts +158 -0
- package/src/stsoauth2manager.ts +373 -0
- package/src/stsoauth2types.ts +111 -0
- package/src/stsoauth2worker.ts +583 -0
- package/tsconfig.json +32 -0
- package/vite.config.ts +62 -0
- package/dist/stsoauth2plugin.es.js +0 -12300
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nsshunt/stsoauth2plugin",
|
|
3
|
+
"files": [
|
|
4
|
+
"dist",
|
|
5
|
+
"types"
|
|
6
|
+
],
|
|
7
|
+
"version": "0.1.38",
|
|
8
|
+
"description": "STS OAuth2 VUE Plugin",
|
|
9
|
+
"module": "./dist/stsoauth2plugin.es.js",
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/stsoauth2plugin.es.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"lint": "eslint . --ext js,jsx,ts,tsx --fix",
|
|
18
|
+
"test": "jest --detectOpenHandles --no-cache",
|
|
19
|
+
"testwatch": "jest --watchAll --detectOpenHandles --no-cache",
|
|
20
|
+
"build2": "tsc",
|
|
21
|
+
"build": "tsc && vite build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/nsshunt/stsoauth2plugin.git"
|
|
26
|
+
},
|
|
27
|
+
"author": "STS",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/nsshunt/stsoauth2plugin/issues"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@babel/preset-env": "^7.18.2",
|
|
34
|
+
"@babel/preset-typescript": "^7.17.12",
|
|
35
|
+
"@tsconfig/node18": "^1.0.0",
|
|
36
|
+
"@types/debug": "^4.1.7",
|
|
37
|
+
"@types/jest": "^28.1.1",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.28.0",
|
|
40
|
+
"eslint": "^8.16.0",
|
|
41
|
+
"jest": "^28.0.2",
|
|
42
|
+
"prettier": "^2.7.1",
|
|
43
|
+
"supertest": "^6.2.2",
|
|
44
|
+
"ts-loader": "^9.3.0",
|
|
45
|
+
"typescript": "^4.7.3"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/nsshunt/stsoauth2plugin#readme",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@nsshunt/stsinstrumentation": "^6.11.1",
|
|
50
|
+
"@nsshunt/stsutils": "^1.15.1",
|
|
51
|
+
"axios": "^0.27.2",
|
|
52
|
+
"debug": "^4.3.4",
|
|
53
|
+
"es-cookie": "^1.3.2",
|
|
54
|
+
"http-status-codes": "^2.2.0",
|
|
55
|
+
"jwt-decode": "^3.1.2",
|
|
56
|
+
"vite": "^2.9.12"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsoauth2plugin",
|
|
3
|
-
"
|
|
4
|
-
"dist",
|
|
5
|
-
"types"
|
|
6
|
-
],
|
|
7
|
-
"version": "0.1.38",
|
|
3
|
+
"version": "0.1.39",
|
|
8
4
|
"description": "STS OAuth2 VUE Plugin",
|
|
9
|
-
"
|
|
5
|
+
"main": "dist/index.js",
|
|
10
6
|
"types": "./types/index.d.ts",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./dist/stsoauth2plugin.es.js"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
7
|
"scripts": {
|
|
17
8
|
"lint": "eslint . --ext js,jsx,ts,tsx --fix",
|
|
18
9
|
"test": "jest --detectOpenHandles --no-cache",
|
|
19
10
|
"testwatch": "jest --watchAll --detectOpenHandles --no-cache",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"build2": "tsc && vite build"
|
|
22
13
|
},
|
|
23
14
|
"repository": {
|
|
24
15
|
"type": "git",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class CryptoUtils {
|
|
2
|
+
DigestMessage = async function (message) {
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
const data = encoder.encode(message);
|
|
5
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
6
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
|
|
7
|
+
//let b64 = window.btoa(String.fromCharCode(...hashArray));
|
|
8
|
+
const b64 = btoa(String.fromCharCode(...hashArray));// Use below if a HEX string is required
|
|
9
|
+
// const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
|
|
10
|
+
return b64;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
CreateRandomString = (size = 43) => {
|
|
14
|
+
//const randomValues = Array.from(window.crypto.getRandomValues(new Uint8Array(size)))
|
|
15
|
+
const randomValues = Array.from(crypto.getRandomValues(new Uint8Array(size)))
|
|
16
|
+
//let b64 = window.btoa(String.fromCharCode(...randomValues));
|
|
17
|
+
const b64 = btoa(String.fromCharCode(...randomValues));
|
|
18
|
+
return b64;
|
|
19
|
+
//return randomValues.toString('base64');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
CreateRandomStringEx = () => {
|
|
23
|
+
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.';
|
|
24
|
+
let random = '';
|
|
25
|
+
//const randomValues = Array.from(window.crypto.getRandomValues(new Uint8Array(43)));
|
|
26
|
+
const randomValues = Array.from(crypto.getRandomValues(new Uint8Array(43)));
|
|
27
|
+
randomValues.forEach(v => (random += charset[v % charset.length]));
|
|
28
|
+
return random;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default CryptoUtils
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// https://github.com/auth0/auth0-spa-js/blob/1de6427f81a8c5b005e9b6d10b9efb1e73542528/static/index.html
|
|
2
|
+
// https://stackoverflow.com/questions/12446317/change-url-without-redirecting-using-javascript
|
|
3
|
+
class QueryParams {
|
|
4
|
+
DecodeQueryParams = (params) => {
|
|
5
|
+
const retObj = { };
|
|
6
|
+
const arr = Object.keys(params)
|
|
7
|
+
.filter(k => typeof params[k] !== 'undefined')
|
|
8
|
+
.map(k => {
|
|
9
|
+
retObj[decodeURIComponent(k)] = decodeURIComponent(params[k]);
|
|
10
|
+
});
|
|
11
|
+
return retObj;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
CreateQueryParams = (params) => {
|
|
15
|
+
return Object.keys(params)
|
|
16
|
+
.filter(k => typeof params[k] !== 'undefined')
|
|
17
|
+
.map(k => {
|
|
18
|
+
if (Array.isArray(params[k])) {
|
|
19
|
+
return encodeURIComponent(k) + '=' + encodeURIComponent(params[k].join(' '))
|
|
20
|
+
} else {
|
|
21
|
+
return encodeURIComponent(k) + '=' + encodeURIComponent(params[k])
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.join('&');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_GetQueryParams = (param) => {
|
|
28
|
+
let retVal = { };
|
|
29
|
+
const uri = param.split("?");
|
|
30
|
+
if (uri.length == 2) {
|
|
31
|
+
const vars = uri[1].split("&");
|
|
32
|
+
const getVars = {};
|
|
33
|
+
let tmp = "";
|
|
34
|
+
vars.forEach(function (v) {
|
|
35
|
+
tmp = v.split("=");
|
|
36
|
+
if (tmp.length == 2) getVars[tmp[0]] = tmp[1];
|
|
37
|
+
});
|
|
38
|
+
retVal = this.DecodeQueryParams(getVars);
|
|
39
|
+
}
|
|
40
|
+
return retVal;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
GetQueryParams = () => {
|
|
44
|
+
return this._GetQueryParams(window.location.href);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default QueryParams;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { STSOAuth2Manager } from './stsoauth2manager'
|
|
2
|
+
|
|
3
|
+
export * from './stsoauth2types'
|
|
4
|
+
export * from './stsoauth2manager'
|
|
5
|
+
export * from './stsoauth2worker'
|
|
6
|
+
|
|
7
|
+
export const STSOAuth2ManagerPlugin = {
|
|
8
|
+
install: (app, router) => {
|
|
9
|
+
const om = new STSOAuth2Manager(app, router);
|
|
10
|
+
app.config.globalProperties.$sts.om = om;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import Debug from "debug";
|
|
2
|
+
const debug = Debug(`proc:${process.pid}:storage.ts`);
|
|
3
|
+
|
|
4
|
+
import * as Cookies from 'es-cookie';
|
|
5
|
+
import { JSONObject } from "@nsshunt/stsutils";
|
|
6
|
+
|
|
7
|
+
export interface IStsStorage<T> {
|
|
8
|
+
get(key: string): T
|
|
9
|
+
set(key: string, value: T, options?: JSONObject): void
|
|
10
|
+
remove(key: string): void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum ClientStorageType {
|
|
14
|
+
LOCAL_STORAGE = 'LocalStorage', //@@ todo
|
|
15
|
+
SESSION_STORAGE = 'SessionStorage',
|
|
16
|
+
COOKIE_STORAGE = 'CookieStorage',
|
|
17
|
+
MEMORY_STORAGE = 'MemoryStorage' //@@ todo
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class CookieStorage<T> implements IStsStorage<T>
|
|
21
|
+
{
|
|
22
|
+
get = (key: string): T => {
|
|
23
|
+
const raw = Cookies.get(key);
|
|
24
|
+
if (raw) {
|
|
25
|
+
return JSON.parse(raw);
|
|
26
|
+
} else {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
set = (key: string, value: T, options: JSONObject = { }) => {
|
|
32
|
+
let cookieAttributes: Cookies.CookieAttributes = { };
|
|
33
|
+
if ('https:' === window.location.protocol) {
|
|
34
|
+
cookieAttributes = {
|
|
35
|
+
secure: true,
|
|
36
|
+
sameSite: 'none'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (options && options.daysUntilExpire) {
|
|
41
|
+
cookieAttributes.expires = options.daysUntilExpire;
|
|
42
|
+
} else {
|
|
43
|
+
cookieAttributes.expires = 1;
|
|
44
|
+
}
|
|
45
|
+
debug(`CookieStorage.set: key: ${key}, value: [${value}]`);
|
|
46
|
+
Cookies.set(key, JSON.stringify(value), cookieAttributes);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
remove = (key: string): void => {
|
|
50
|
+
Cookies.remove(key);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class SessionStorage<T> implements IStsStorage<T>
|
|
55
|
+
{
|
|
56
|
+
get = (key: string): T => {
|
|
57
|
+
const value: string = sessionStorage.getItem(key);
|
|
58
|
+
if (typeof value === 'undefined') {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
if (value === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return JSON.parse(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
set = (key: string, value: T): void => {
|
|
68
|
+
debug(`SessionStorage.set: key: ${key}, value: [${value}]`);
|
|
69
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
remove = (key: string): void => {
|
|
73
|
+
sessionStorage.removeItem(key);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
class LocalStorage<T> implements IStsStorage<T>
|
|
78
|
+
{
|
|
79
|
+
get = (key: string): T => {
|
|
80
|
+
const value: string = localStorage.getItem(key);
|
|
81
|
+
if (typeof value === 'undefined') {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (value === null) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return JSON.parse(value);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
set = (key: string, value: T): void => {
|
|
91
|
+
debug(`LocalStorage.set: key: ${key}, value: [${value}]`);
|
|
92
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
remove = (key: string): void => {
|
|
96
|
+
localStorage.removeItem(key);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class MemoryStorage<T> implements IStsStorage<T>
|
|
101
|
+
{
|
|
102
|
+
#store: Record<string, T> = { };
|
|
103
|
+
|
|
104
|
+
get = (key: string): T => {
|
|
105
|
+
const value: T = this.#store[key];
|
|
106
|
+
if (typeof value === 'undefined') {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (value === null) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
set = (key: string, value: T): void => {
|
|
116
|
+
debug(`MemoryStorage.set: key: ${key}, value: [${value}]`);
|
|
117
|
+
this.#store[key] = value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
remove = (key: string): void => {
|
|
121
|
+
delete this.#store[key];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export class ClientStorageOptions {
|
|
126
|
+
clientStorageType: ClientStorageType = ClientStorageType.MEMORY_STORAGE;
|
|
127
|
+
storageOptions?: JSONObject
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export class ClientStorageFactory<T>
|
|
131
|
+
{
|
|
132
|
+
#storage = null;
|
|
133
|
+
|
|
134
|
+
constructor(options: ClientStorageOptions) {
|
|
135
|
+
switch (options.clientStorageType) {
|
|
136
|
+
case ClientStorageType.SESSION_STORAGE :
|
|
137
|
+
this.#storage = new SessionStorage<T>();
|
|
138
|
+
break;
|
|
139
|
+
case ClientStorageType.LOCAL_STORAGE :
|
|
140
|
+
this.#storage = new LocalStorage<T>();
|
|
141
|
+
break;
|
|
142
|
+
case ClientStorageType.COOKIE_STORAGE :
|
|
143
|
+
this.#storage = new CookieStorage<T>();
|
|
144
|
+
break;
|
|
145
|
+
case ClientStorageType.MEMORY_STORAGE :
|
|
146
|
+
this.#storage = new MemoryStorage<T>();
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
throw new Error(`Unknown [${options.clientStorageType}] storage type.`);
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
GetStorage(): IStsStorage<T>
|
|
155
|
+
{
|
|
156
|
+
return this.#storage;
|
|
157
|
+
}
|
|
158
|
+
}
|