@nsshunt/stsutils 1.8.1 → 1.8.4
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/authutilsbrowser.js +2 -23
- package/index.js +2 -2
- package/oauth2terms.js +36 -7
- package/package.json +1 -1
package/authutilsbrowser.js
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
const debug = require('debug')(`stsutils`);
|
|
2
|
-
const colors = require('colors');
|
|
3
2
|
const axios = require('axios');
|
|
4
3
|
|
|
5
4
|
class AuthUtilsBrowser
|
|
6
5
|
{
|
|
7
|
-
constructor()
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#GetDurationColour(duration)
|
|
13
|
-
{
|
|
14
|
-
if (duration > 250) {
|
|
15
|
-
return colors.red;
|
|
16
|
-
} else if (duration > 150) {
|
|
17
|
-
return colors.magenta;
|
|
18
|
-
} else if (duration > 50) {
|
|
19
|
-
return colors.blue;
|
|
20
|
-
} else if (duration > 10) {
|
|
21
|
-
return colors.green;
|
|
22
|
-
} else {
|
|
23
|
-
return colors.black;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
6
|
LoginBrowser = async (options) => {
|
|
28
7
|
const { authendpoint, authUserName, authUserEMail, authUserPassword, defaultTimeout, publishDebug } = options;
|
|
29
8
|
try {
|
|
@@ -38,7 +17,7 @@ class AuthUtilsBrowser
|
|
|
38
17
|
,timeout: defaultTimeout
|
|
39
18
|
});
|
|
40
19
|
duration = (performance.now() - processStart).toFixed(4);
|
|
41
|
-
if (publishDebug) debug(
|
|
20
|
+
if (publishDebug) debug(`AuthUtilsBrowser.LoginBrowser request duration: [${duration}]`);
|
|
42
21
|
accessToken = retVal.data.detail.token;
|
|
43
22
|
return {
|
|
44
23
|
accessToken: accessToken,
|
|
@@ -71,7 +50,7 @@ class AuthUtilsBrowser
|
|
|
71
50
|
,withCredentials: true
|
|
72
51
|
});
|
|
73
52
|
duration = (performance.now() - processStart).toFixed(4);
|
|
74
|
-
if (publishDebug) debug(
|
|
53
|
+
if (publishDebug) debug(`AuthUtilsBrowser.RefreshAuthTokenBrowser request duration: [${duration}]`);
|
|
75
54
|
accessToken = retVal.data.detail.token;
|
|
76
55
|
return {
|
|
77
56
|
accessToken: accessToken,
|
package/index.js
CHANGED
|
@@ -4,9 +4,9 @@ const AuthUtilsBrowser = require('./authutilsbrowser.js');
|
|
|
4
4
|
const STSOptionsBase = require('./stsoptionsbase.js');
|
|
5
5
|
const { AddSchema, Validate } = require('./validate.js');
|
|
6
6
|
const GetErrorPayload = require('./errorhandling.js');
|
|
7
|
-
const { OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim,
|
|
7
|
+
const { OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, compareParameterTypes } = require('./oauth2terms.js');
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
10
10
|
sleep, status, STSOptionsBase, AuthUtilsBrowser, AddSchema, Validate, GetErrorPayload,
|
|
11
|
-
OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim,
|
|
11
|
+
OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, compareParameterTypes
|
|
12
12
|
};
|
package/oauth2terms.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Ref: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A
|
|
2
2
|
const OAuth2ParameterType = Object.freeze({
|
|
3
|
-
AUDIENCE: 'AUDIENCE',
|
|
3
|
+
AUDIENCE: 'AUDIENCE', // STS Extension
|
|
4
4
|
CLIENT_ID: 'client_id',
|
|
5
5
|
CLIENT_SECRET: 'client_secret',
|
|
6
6
|
RESPONSE_TYPE: 'response_type',
|
|
@@ -9,6 +9,7 @@ const OAuth2ParameterType = Object.freeze({
|
|
|
9
9
|
REDIRECT_URI: 'redirect_uri',
|
|
10
10
|
ERROR: 'error',
|
|
11
11
|
ERROR_DESCRIPTION: 'error_description',
|
|
12
|
+
ERROR_CODES: 'error_codes', // STS Extension
|
|
12
13
|
ERROR_URI: 'error_uri',
|
|
13
14
|
GRANT_TYPE: 'grant_type',
|
|
14
15
|
CODE: 'code',
|
|
@@ -18,7 +19,29 @@ const OAuth2ParameterType = Object.freeze({
|
|
|
18
19
|
USERNAME: 'username',
|
|
19
20
|
PASSWORD: 'password',
|
|
20
21
|
REFRESH_TOKEN: 'refresh_token',
|
|
21
|
-
RESPONSE_MODE: 'response_mode'
|
|
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
|
+
}
|
|
22
45
|
});
|
|
23
46
|
|
|
24
47
|
// OIDC Standard Claims
|
|
@@ -43,7 +66,8 @@ const OIDCStandardClaim = Object.freeze({
|
|
|
43
66
|
PHONE_NUMBER: 'phone_number',
|
|
44
67
|
PHONE_NUMBER_VERIFIED: 'phone_number_verified',
|
|
45
68
|
ADDRESS: 'address',
|
|
46
|
-
CLIENT_SECRET: '
|
|
69
|
+
CLIENT_SECRET: 'client_secret',
|
|
70
|
+
NONCE: 'nonce' // STS Extension
|
|
47
71
|
});
|
|
48
72
|
|
|
49
73
|
const OIDCAddressClaim = Object.freeze({
|
|
@@ -54,14 +78,19 @@ const OIDCAddressClaim = Object.freeze({
|
|
|
54
78
|
COUNTRY: 'country'
|
|
55
79
|
});
|
|
56
80
|
|
|
57
|
-
const
|
|
81
|
+
const compareParameterTypes = (source1, source2, authParameterTypes) => {
|
|
58
82
|
let errors = [ ];
|
|
59
83
|
authParameterTypes.forEach(authParameterType => {
|
|
60
|
-
if (source1[authParameterType.paramaterType].localeCompare(source2[authParameterType
|
|
61
|
-
errors.push(
|
|
84
|
+
if (source1[authParameterType.paramaterType].localeCompare(source2[authParameterType]) !== 0) {
|
|
85
|
+
errors.push({
|
|
86
|
+
[OAuth2ParameterType.ERROR]: OAuth2ParameterErrorType.NOT_EQUAL.description,
|
|
87
|
+
[OAuth2ParameterType.ERROR_DESCRIPTION]: `${OAuth2ParameterErrorType.NOT_EQUAL.description}: Parameter: [${authParameterType}]`,
|
|
88
|
+
[OAuth2ParameterType.ERROR_CODES]: OAuth2ParameterErrorType.NOT_EQUAL.code,
|
|
89
|
+
[OAuth2ParameterType.TIMESTAMP]: Date.now(),
|
|
90
|
+
})
|
|
62
91
|
}
|
|
63
92
|
});
|
|
64
93
|
return errors;
|
|
65
94
|
}
|
|
66
95
|
|
|
67
|
-
module.exports = { OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim,
|
|
96
|
+
module.exports = { OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, OAuth2ParameterErrorType, compareParameterTypes }
|