@nsshunt/stsutils 1.7.3 → 1.8.0

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.
@@ -10,11 +10,4 @@ updates:
10
10
  - package-ecosystem: "npm" # See documentation for possible values
11
11
  directory: "/" # Location of package manifests
12
12
  schedule:
13
- interval: "weekly"
14
-
15
- - package-ecosystem: "github-actions"
16
- # Workflow files stored in the
17
- # default location of `.github/workflows`
18
- directory: "/"
19
- schedule:
20
- interval: "weekly"
13
+ interval: "monthly"
@@ -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, compareParameterType } = require('./oauth2terms.js');
6
8
 
7
- module.exports = { sleep, status, STSOptionsBase, AuthUtilsBrowser, AddSchema, Validate };
9
+ module.exports = {
10
+ sleep, status, STSOptionsBase, AuthUtilsBrowser, AddSchema, Validate, GetErrorPayload,
11
+ OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, compareParameterType
12
+ };
package/oauth2terms.js ADDED
@@ -0,0 +1,66 @@
1
+ // Ref: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A
2
+ const OAuth2ParameterType = Object.freeze({
3
+ CLIENT_ID: 'client_id',
4
+ CLIENT_SECRET: 'client_secret',
5
+ RESPONSE_TYPE: 'response_type',
6
+ SCOPE: 'scope',
7
+ STATE: 'state',
8
+ REDIRECT_URI: 'redirect_uri',
9
+ ERROR: 'error',
10
+ ERROR_DESCRIPTION: 'error_description',
11
+ ERROR_URI: 'error_uri',
12
+ GRANT_TYPE: 'grant_type',
13
+ CODE: 'code',
14
+ ACCESS_TOKEN: 'access_token',
15
+ TOKEN_TYPE: 'token_type',
16
+ EXPIRES_IN: 'expires_in',
17
+ USERNAME: 'username',
18
+ PASSWORD: 'password',
19
+ REFRESH_TOKEN: 'refresh_token',
20
+ RESPONSE_MODE: 'response_mode'
21
+ });
22
+
23
+ // OIDC Standard Claims
24
+ // Ref: https://openid.net/specs/openid-connect-core-1_0.html#Claims
25
+ const OIDCStandardClaim = Object.freeze({
26
+ SUB: 'sub',
27
+ NAME: 'name',
28
+ GIVEN_NAME: 'given_name',
29
+ FAMILY_NAME: 'family_name',
30
+ MIDDLE_NAME: 'middle_name',
31
+ NICKNAME: 'nickname',
32
+ PREFERRED_USERNAME: 'preferred_username',
33
+ PROFILE: 'profile',
34
+ PICTURE: 'picture',
35
+ WEBSITE: 'website',
36
+ EMAIL: 'email',
37
+ EMAIL_VERIFIED: 'email_verified',
38
+ GENDER: 'gender',
39
+ BIRTHDATE: 'birthdate',
40
+ ZONEINFO: 'zoneinfo',
41
+ LOCALE: 'locale',
42
+ PHONE_NUMBER: 'phone_number',
43
+ PHONE_NUMBER_VERIFIED: 'phone_number_verified',
44
+ ADDRESS: 'address',
45
+ CLIENT_SECRET: 'updated_at'
46
+ });
47
+
48
+ const OIDCAddressClaim = Object.freeze({
49
+ FORMATTED: 'formatted',
50
+ STREET_ADDRESS: 'street_address',
51
+ LOCALITY: 'locality',
52
+ REGION: 'region',
53
+ COUNTRY: 'country'
54
+ });
55
+
56
+ const compareParameterType = (source1, source2, authParameterTypes) => {
57
+ let errors = [ ];
58
+ authParameterTypes.forEach(authParameterType => {
59
+ if (source1[authParameterType.paramaterType].localeCompare(source2[authParameterType.paramaterType]) !== 0) {
60
+ errors.push(authParameterType.errorType);
61
+ }
62
+ });
63
+ return errors;
64
+ }
65
+
66
+ module.exports = { OAuth2ParameterType, OIDCStandardClaim, OIDCAddressClaim, compareParameterType }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsshunt/stsutils",
3
- "version": "1.7.3",
3
+ "version": "1.8.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,17 +22,17 @@
22
22
  "parser": "@babel/eslint-parser"
23
23
  },
24
24
  "devDependencies": {
25
- "@babel/core": "^7.17.5",
25
+ "@babel/core": "^7.17.8",
26
26
  "@babel/eslint-parser": "^7.17.0",
27
27
  "@babel/plugin-proposal-class-properties": "^7.16.7",
28
28
  "@babel/plugin-proposal-private-methods": "^7.16.11",
29
- "eslint": "^8.10.0",
29
+ "eslint": "^8.11.0",
30
30
  "jest": "^27.5.1"
31
31
  },
32
32
  "dependencies": {
33
- "ajv": "^8.10.0",
34
- "axios": "^0.26.0",
33
+ "ajv": "^8.11.0",
34
+ "axios": "^0.26.1",
35
35
  "colors": "^1.4.0",
36
- "debug": "^4.3.3"
36
+ "debug": "^4.3.4"
37
37
  }
38
38
  }
package/validate.js CHANGED
@@ -5,12 +5,17 @@ const ajv = new Ajv();
5
5
  const _Validate = (validator, payload) => {
6
6
  const valid = validator(payload);
7
7
  if (!valid) {
8
+ return validator.errors;
9
+ } else {
10
+ return null;
11
+ }
12
+ /*
8
13
  console.error(validator.errors);
9
14
  console.trace('Invalid Schema');
10
15
  console.log('Payload:-');
11
16
  console.log(JSON.stringify(payload));
12
17
  process.exit(1);
13
- }
18
+ */
14
19
  };
15
20
 
16
21
  const AddSchema = (name, schema) => {
@@ -23,7 +28,7 @@ const AddSchema = (name, schema) => {
23
28
 
24
29
  const Validate = (name, payload) => {
25
30
  const validator = ajv.getSchema(name)
26
- _Validate(validator, payload);
31
+ return _Validate(validator, payload);
27
32
  };
28
33
 
29
34
  module.exports = { AddSchema, Validate };