@nsshunt/stsutils 1.7.6 → 1.8.2
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/errorhandling.js +12 -0
- package/index.js +6 -1
- package/oauth2terms.js +95 -0
- package/package.json +2 -2
package/errorhandling.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const GetErrorPayload = (errorCode, details = null) => {
|
|
2
|
+
return {
|
|
3
|
+
error: errorCode.code,
|
|
4
|
+
error_description: errorCode.description,
|
|
5
|
+
timestamp: Date.now(),
|
|
6
|
+
//trace_id: "255d1aef-8c98-452f-ac51-23d051240864", //@@
|
|
7
|
+
//correlation_id: "fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7", //@@
|
|
8
|
+
details: details
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = GetErrorPayload;
|
package/index.js
CHANGED
|
@@ -3,5 +3,10 @@ let status = require('./status.js');
|
|
|
3
3
|
const AuthUtilsBrowser = require('./authutilsbrowser.js');
|
|
4
4
|
const STSOptionsBase = require('./stsoptionsbase.js');
|
|
5
5
|
const { AddSchema, Validate } = require('./validate.js');
|
|
6
|
+
const GetErrorPayload = require('./errorhandling.js');
|
|
7
|
+
const { OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, compareParameterTypes } = require('./oauth2terms.js');
|
|
6
8
|
|
|
7
|
-
module.exports = {
|
|
9
|
+
module.exports = {
|
|
10
|
+
sleep, status, STSOptionsBase, AuthUtilsBrowser, AddSchema, Validate, GetErrorPayload,
|
|
11
|
+
OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, compareParameterTypes
|
|
12
|
+
};
|
package/oauth2terms.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Ref: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A
|
|
2
|
+
const OAuth2ParameterType = Object.freeze({
|
|
3
|
+
AUDIENCE: 'AUDIENCE', // STS Extension
|
|
4
|
+
CLIENT_ID: 'client_id',
|
|
5
|
+
CLIENT_SECRET: 'client_secret',
|
|
6
|
+
RESPONSE_TYPE: 'response_type',
|
|
7
|
+
SCOPE: 'scope',
|
|
8
|
+
STATE: 'state',
|
|
9
|
+
REDIRECT_URI: 'redirect_uri',
|
|
10
|
+
ERROR: 'error',
|
|
11
|
+
ERROR_DESCRIPTION: 'error_description',
|
|
12
|
+
ERROR_CODES: 'error_codes', // STS Extension
|
|
13
|
+
ERROR_URI: 'error_uri',
|
|
14
|
+
GRANT_TYPE: 'grant_type',
|
|
15
|
+
CODE: 'code',
|
|
16
|
+
ACCESS_TOKEN: 'access_token',
|
|
17
|
+
TOKEN_TYPE: 'token_type',
|
|
18
|
+
EXPIRES_IN: 'expires_in',
|
|
19
|
+
USERNAME: 'username',
|
|
20
|
+
PASSWORD: 'password',
|
|
21
|
+
REFRESH_TOKEN: 'refresh_token',
|
|
22
|
+
RESPONSE_MODE: 'response_mode', // STS Extension
|
|
23
|
+
TIMESTAMP: 'timestamp', // STS Extension
|
|
24
|
+
TRACE_ID: 'trace_id', // STS Extension
|
|
25
|
+
CORRELATION_ID: 'correlation_id' // STS Extension
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const OAuth2ParameterErrorType = Object.freeze({
|
|
29
|
+
NOT_EQUAL: {
|
|
30
|
+
code: 'STS_OAUTH2_ERR_0001',
|
|
31
|
+
description: 'Parameter values not equal.'
|
|
32
|
+
},
|
|
33
|
+
NOT_PRESENT: {
|
|
34
|
+
code: 'STS_OAUTH2_ERR_0002',
|
|
35
|
+
description: 'Parameter not provided.'
|
|
36
|
+
},
|
|
37
|
+
INVALID_FORMAT: {
|
|
38
|
+
code: 'STS_OAUTH2_ERR_0003',
|
|
39
|
+
description: 'Parameter value format invalid.'
|
|
40
|
+
},
|
|
41
|
+
EXPIRED: {
|
|
42
|
+
code: 'STS_OAUTH2_ERR_0004',
|
|
43
|
+
description: 'Parameter value expired.'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// OIDC Standard Claims
|
|
48
|
+
// Ref: https://openid.net/specs/openid-connect-core-1_0.html#Claims
|
|
49
|
+
const OIDCStandardClaim = Object.freeze({
|
|
50
|
+
SUB: 'sub',
|
|
51
|
+
NAME: 'name',
|
|
52
|
+
GIVEN_NAME: 'given_name',
|
|
53
|
+
FAMILY_NAME: 'family_name',
|
|
54
|
+
MIDDLE_NAME: 'middle_name',
|
|
55
|
+
NICKNAME: 'nickname',
|
|
56
|
+
PREFERRED_USERNAME: 'preferred_username',
|
|
57
|
+
PROFILE: 'profile',
|
|
58
|
+
PICTURE: 'picture',
|
|
59
|
+
WEBSITE: 'website',
|
|
60
|
+
EMAIL: 'email',
|
|
61
|
+
EMAIL_VERIFIED: 'email_verified',
|
|
62
|
+
GENDER: 'gender',
|
|
63
|
+
BIRTHDATE: 'birthdate',
|
|
64
|
+
ZONEINFO: 'zoneinfo',
|
|
65
|
+
LOCALE: 'locale',
|
|
66
|
+
PHONE_NUMBER: 'phone_number',
|
|
67
|
+
PHONE_NUMBER_VERIFIED: 'phone_number_verified',
|
|
68
|
+
ADDRESS: 'address',
|
|
69
|
+
CLIENT_SECRET: 'updated_at'
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const OIDCAddressClaim = Object.freeze({
|
|
73
|
+
FORMATTED: 'formatted',
|
|
74
|
+
STREET_ADDRESS: 'street_address',
|
|
75
|
+
LOCALITY: 'locality',
|
|
76
|
+
REGION: 'region',
|
|
77
|
+
COUNTRY: 'country'
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const compareParameterTypes = (source1, source2, authParameterTypes) => {
|
|
81
|
+
let errors = [ ];
|
|
82
|
+
authParameterTypes.forEach(authParameterType => {
|
|
83
|
+
if (source1[authParameterType.paramaterType].localeCompare(source2[authParameterType]) !== 0) {
|
|
84
|
+
errors.push({
|
|
85
|
+
[OAuth2ParameterType.ERROR]: OAuth2ParameterErrorType.NOT_EQUAL.description,
|
|
86
|
+
[OAuth2ParameterType.ERROR_DESCRIPTION]: `${OAuth2ParameterErrorType.NOT_EQUAL.description}: Parameter: [${authParameterType}]`,
|
|
87
|
+
[OAuth2ParameterType.ERROR_CODES]: OAuth2ParameterErrorType.NOT_EQUAL.code,
|
|
88
|
+
[OAuth2ParameterType.TIMESTAMP]: Date.now(),
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return errors;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = { OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, OAuth2ParameterErrorType, compareParameterTypes }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsutils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"jest": "^27.5.1"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"ajv": "^8.
|
|
33
|
+
"ajv": "^8.11.0",
|
|
34
34
|
"axios": "^0.26.1",
|
|
35
35
|
"colors": "^1.4.0",
|
|
36
36
|
"debug": "^4.3.4"
|