@rockcarver/frodo-lib 0.11.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.
Files changed (112) hide show
  1. package/.eslintrc +32 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +30 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. package/.github/README.md +121 -0
  5. package/.github/workflows/pipeline.yml +287 -0
  6. package/.prettierrc +6 -0
  7. package/CHANGELOG.md +512 -0
  8. package/CODE_OF_CONDUCT.md +128 -0
  9. package/LICENSE +21 -0
  10. package/README.md +8 -0
  11. package/docs/CONTRIBUTE.md +96 -0
  12. package/docs/PIPELINE.md +169 -0
  13. package/docs/images/npm_versioning_guidelines.png +0 -0
  14. package/docs/images/release_pipeline.png +0 -0
  15. package/jsconfig.json +6 -0
  16. package/package.json +95 -0
  17. package/resources/sampleEntitiesFile.json +8 -0
  18. package/resources/sampleEnvFile.env +2 -0
  19. package/src/api/AuthenticateApi.js +33 -0
  20. package/src/api/BaseApi.js +242 -0
  21. package/src/api/CirclesOfTrustApi.js +87 -0
  22. package/src/api/EmailTemplateApi.js +37 -0
  23. package/src/api/IdmConfigApi.js +88 -0
  24. package/src/api/LogApi.js +45 -0
  25. package/src/api/ManagedObjectApi.js +62 -0
  26. package/src/api/OAuth2ClientApi.js +69 -0
  27. package/src/api/OAuth2OIDCApi.js +73 -0
  28. package/src/api/OAuth2ProviderApi.js +32 -0
  29. package/src/api/RealmApi.js +99 -0
  30. package/src/api/Saml2Api.js +176 -0
  31. package/src/api/ScriptApi.js +84 -0
  32. package/src/api/SecretsApi.js +151 -0
  33. package/src/api/ServerInfoApi.js +41 -0
  34. package/src/api/SocialIdentityProvidersApi.js +114 -0
  35. package/src/api/StartupApi.js +45 -0
  36. package/src/api/ThemeApi.js +181 -0
  37. package/src/api/TreeApi.js +207 -0
  38. package/src/api/VariablesApi.js +104 -0
  39. package/src/api/utils/ApiUtils.js +77 -0
  40. package/src/api/utils/ApiUtils.test.js +96 -0
  41. package/src/api/utils/Base64.js +62 -0
  42. package/src/index.js +32 -0
  43. package/src/index.test.js +13 -0
  44. package/src/ops/AdminOps.js +901 -0
  45. package/src/ops/AuthenticateOps.js +342 -0
  46. package/src/ops/CirclesOfTrustOps.js +350 -0
  47. package/src/ops/ConnectionProfileOps.js +254 -0
  48. package/src/ops/EmailTemplateOps.js +326 -0
  49. package/src/ops/IdmOps.js +227 -0
  50. package/src/ops/IdpOps.js +342 -0
  51. package/src/ops/JourneyOps.js +2026 -0
  52. package/src/ops/LogOps.js +357 -0
  53. package/src/ops/ManagedObjectOps.js +34 -0
  54. package/src/ops/OAuth2ClientOps.js +151 -0
  55. package/src/ops/OrganizationOps.js +85 -0
  56. package/src/ops/RealmOps.js +139 -0
  57. package/src/ops/SamlOps.js +541 -0
  58. package/src/ops/ScriptOps.js +211 -0
  59. package/src/ops/SecretsOps.js +288 -0
  60. package/src/ops/StartupOps.js +114 -0
  61. package/src/ops/ThemeOps.js +379 -0
  62. package/src/ops/VariablesOps.js +185 -0
  63. package/src/ops/templates/OAuth2ClientTemplate.json +270 -0
  64. package/src/ops/templates/OrgModelUserAttributesTemplate.json +149 -0
  65. package/src/ops/templates/cloud/GenericExtensionAttributesTemplate.json +392 -0
  66. package/src/ops/templates/cloud/managed.json +4119 -0
  67. package/src/ops/utils/Console.js +434 -0
  68. package/src/ops/utils/DataProtection.js +92 -0
  69. package/src/ops/utils/DataProtection.test.js +28 -0
  70. package/src/ops/utils/ExportImportUtils.js +146 -0
  71. package/src/ops/utils/ExportImportUtils.test.js +119 -0
  72. package/src/ops/utils/OpsUtils.js +76 -0
  73. package/src/ops/utils/Wordwrap.js +11 -0
  74. package/src/storage/SessionStorage.js +45 -0
  75. package/src/storage/StaticStorage.js +15 -0
  76. package/test/e2e/journey/baseline/ForgottenUsername.journey.json +216 -0
  77. package/test/e2e/journey/baseline/Login.journey.json +205 -0
  78. package/test/e2e/journey/baseline/PasswordGrant.journey.json +139 -0
  79. package/test/e2e/journey/baseline/ProgressiveProfile.journey.json +198 -0
  80. package/test/e2e/journey/baseline/Registration.journey.json +249 -0
  81. package/test/e2e/journey/baseline/ResetPassword.journey.json +268 -0
  82. package/test/e2e/journey/baseline/UpdatePassword.journey.json +323 -0
  83. package/test/e2e/journey/baseline/allAlphaJourneys.journeys.json +1520 -0
  84. package/test/e2e/journey/delete/ForgottenUsername.journey.json +216 -0
  85. package/test/e2e/journey/delete/Login.journey.json +205 -0
  86. package/test/e2e/journey/delete/PasswordGrant.journey.json +139 -0
  87. package/test/e2e/journey/delete/ProgressiveProfile.journey.json +198 -0
  88. package/test/e2e/journey/delete/Registration.journey.json +249 -0
  89. package/test/e2e/journey/delete/ResetPassword.journey.json +268 -0
  90. package/test/e2e/journey/delete/UpdatePassword.journey.json +323 -0
  91. package/test/e2e/journey/delete/deleteMe.journey.json +230 -0
  92. package/test/e2e/journey/list/Disabled.journey.json +43 -0
  93. package/test/e2e/journey/list/ForgottenUsername.journey.json +216 -0
  94. package/test/e2e/journey/list/Login.journey.json +205 -0
  95. package/test/e2e/journey/list/PasswordGrant.journey.json +139 -0
  96. package/test/e2e/journey/list/ProgressiveProfile.journey.json +198 -0
  97. package/test/e2e/journey/list/Registration.journey.json +249 -0
  98. package/test/e2e/journey/list/ResetPassword.journey.json +268 -0
  99. package/test/e2e/journey/list/UpdatePassword.journey.json +323 -0
  100. package/test/e2e/setup.js +107 -0
  101. package/test/e2e/theme/baseline/Contrast.theme.json +95 -0
  102. package/test/e2e/theme/baseline/Highlander.theme.json +95 -0
  103. package/test/e2e/theme/baseline/Robroy.theme.json +95 -0
  104. package/test/e2e/theme/baseline/Starter-Theme.theme.json +94 -0
  105. package/test/e2e/theme/baseline/Zardoz.theme.json +95 -0
  106. package/test/e2e/theme/import/Contrast.theme.json +95 -0
  107. package/test/e2e/theme/import/Highlander.theme.json +95 -0
  108. package/test/e2e/theme/import/Robroy.theme.json +95 -0
  109. package/test/e2e/theme/import/Starter-Theme.theme.json +94 -0
  110. package/test/e2e/theme/import/Zardoz.default.theme.json +95 -0
  111. package/test/fs_tmp/.gitkeep +2 -0
  112. package/test/global/setup.js +65 -0
@@ -0,0 +1,87 @@
1
+ import util from 'util';
2
+ import _ from 'lodash';
3
+ import { generateAmApi } from './BaseApi.js';
4
+ import { getCurrentRealmPath } from './utils/ApiUtils.js';
5
+ import storage from '../storage/SessionStorage.js';
6
+
7
+ const circleOfTrustByIdURLTemplate =
8
+ '%s/json%s/realm-config/federation/circlesoftrust/%s';
9
+ const createCircleOfTrustURLTemplate =
10
+ '%s/json%s/realm-config/federation/circlesoftrust/?_action=create';
11
+ const queryAllCirclesOfTrustURLTemplate =
12
+ '%s/json%s/realm-config/federation/circlesoftrust?_queryFilter=true';
13
+ const apiVersion = 'protocol=2.1,resource=1.0';
14
+ const getApiConfig = () => {
15
+ const configPath = getCurrentRealmPath();
16
+ return {
17
+ path: `${configPath}/realm-config/federation/circlesoftrust`,
18
+ apiVersion,
19
+ };
20
+ };
21
+
22
+ /**
23
+ * Get all SAML2 circles of trust
24
+ * @returns {Promise} a promise that resolves to an array of circles of trust objects
25
+ */
26
+ export async function getCirclesOfTrust() {
27
+ const urlString = util.format(
28
+ queryAllCirclesOfTrustURLTemplate,
29
+ storage.session.getTenant(),
30
+ getCurrentRealmPath()
31
+ );
32
+ return generateAmApi(getApiConfig()).get(urlString, {
33
+ withCredentials: true,
34
+ });
35
+ }
36
+
37
+ /**
38
+ * Get SAML2 circle of trust by id/name
39
+ * @param {String} cotId Circle of trust id/name
40
+ * @returns {Promise} a promise that resolves to a saml2 circle of trust object
41
+ */
42
+ export async function getCircleOfTrust(cotId) {
43
+ const urlString = util.format(
44
+ circleOfTrustByIdURLTemplate,
45
+ storage.session.getTenant(),
46
+ getCurrentRealmPath(),
47
+ cotId
48
+ );
49
+ return generateAmApi(getApiConfig()).get(urlString, {
50
+ withCredentials: true,
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Create a SAML2 circle of trust
56
+ * @param {Object} cotData Object representing a SAML circle of trust
57
+ * @returns {Promise} a promise that resolves to a saml2 circle of trust object
58
+ */
59
+ export async function createCircleOfTrust(cotData) {
60
+ const postData = _.cloneDeep(cotData);
61
+ const urlString = util.format(
62
+ createCircleOfTrustURLTemplate,
63
+ storage.session.getTenant(),
64
+ getCurrentRealmPath(storage.session.getRealm())
65
+ );
66
+ return generateAmApi(getApiConfig()).post(urlString, postData, {
67
+ withCredentials: true,
68
+ });
69
+ }
70
+
71
+ /**
72
+ * Update SAML2 circle of trust
73
+ * @param {String} cotId Entity provider location (hosted or remote)
74
+ * @param {Object} cotData Object representing a SAML2 circle of trust
75
+ * @returns {Promise} a promise that resolves to a saml2 circle of trust object
76
+ */
77
+ export async function updateCircleOfTrust(cotId, cotData) {
78
+ const urlString = util.format(
79
+ circleOfTrustByIdURLTemplate,
80
+ storage.session.getTenant(),
81
+ getCurrentRealmPath(),
82
+ cotId
83
+ );
84
+ return generateAmApi(getApiConfig()).put(urlString, cotData, {
85
+ withCredentials: true,
86
+ });
87
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ getConfigEntitiesByType,
3
+ getConfigEntity,
4
+ putConfigEntity,
5
+ } from './IdmConfigApi.js';
6
+
7
+ /**
8
+ * Email template type key used to build the IDM id: 'emailTemplate/<id>'
9
+ */
10
+ export const EMAIL_TEMPLATE_TYPE = 'emailTemplate';
11
+
12
+ /**
13
+ * Get all email templates
14
+ * @returns {Promise} a promise that resolves to an object containing an array of email template objects
15
+ */
16
+ export async function getEmailTemplates() {
17
+ return getConfigEntitiesByType(EMAIL_TEMPLATE_TYPE);
18
+ }
19
+
20
+ /**
21
+ * Get email template
22
+ * @param {String} id id/name of the email template without the type prefix
23
+ * @returns {Promise} a promise that resolves to an object containing the email template object
24
+ */
25
+ export async function getEmailTemplate(id) {
26
+ return getConfigEntity(`${EMAIL_TEMPLATE_TYPE}/${id}`);
27
+ }
28
+
29
+ /**
30
+ * Put email template
31
+ * @param {String} id id/name of the email template without the type prefix
32
+ * @param {Object} data email template object
33
+ * @returns {Promise} a promise that resolves to an object containing the email template object
34
+ */
35
+ export async function putEmailTemplate(id, data) {
36
+ return putConfigEntity(`${EMAIL_TEMPLATE_TYPE}/${id}`, data);
37
+ }
@@ -0,0 +1,88 @@
1
+ import util from 'util';
2
+ import { generateIdmApi } from './BaseApi.js';
3
+ import { getTenantURL } from './utils/ApiUtils.js';
4
+ import storage from '../storage/SessionStorage.js';
5
+
6
+ const idmAllConfigURLTemplate = '%s/openidm/config';
7
+ const idmConfigURLTemplate = '%s/openidm/config/%s';
8
+ const idmConfigEntityQueryTemplate = '%s/openidm/config?_queryFilter=%s';
9
+ const idmManagedObjectURLTemplate =
10
+ '%s/openidm/managed/%s?_queryFilter=true&_pageSize=10000';
11
+
12
+ /**
13
+ * Get all IDM config entities
14
+ * @returns {Promise} a promise that resolves to an object containing all IDM config entities
15
+ */
16
+ export async function getAllConfigEntities() {
17
+ const urlString = util.format(
18
+ idmAllConfigURLTemplate,
19
+ getTenantURL(storage.session.getTenant())
20
+ );
21
+ return generateIdmApi().get(urlString);
22
+ }
23
+
24
+ /**
25
+ * Get IDM config entities by type
26
+ * @param {String} type the desired type of config entity
27
+ * @returns {Promise} a promise that resolves to an object containing all IDM config entities of the desired type
28
+ */
29
+ export async function getConfigEntitiesByType(type) {
30
+ const urlString = util.format(
31
+ idmConfigEntityQueryTemplate,
32
+ getTenantURL(storage.session.getTenant()),
33
+ encodeURIComponent(`_id sw '${type}'`)
34
+ );
35
+ return generateIdmApi().get(urlString);
36
+ }
37
+
38
+ /**
39
+ * Get an IDM config entity
40
+ * @param {String} id the desired config entity
41
+ * @returns {Promise} a promise that resolves to an object containing an IDM config entity
42
+ */
43
+ export async function getConfigEntity(id) {
44
+ const urlString = util.format(
45
+ idmConfigURLTemplate,
46
+ getTenantURL(storage.session.getTenant()),
47
+ id
48
+ );
49
+ return generateIdmApi().get(urlString);
50
+ }
51
+
52
+ /**
53
+ * Put IDM config entity
54
+ * @param {String} id config entity id
55
+ * @param {String} data config entity object
56
+ * @returns {Promise} a promise that resolves to an object containing an IDM config entity
57
+ */
58
+ export async function putConfigEntity(id, data) {
59
+ const urlString = util.format(
60
+ idmConfigURLTemplate,
61
+ getTenantURL(storage.session.getTenant()),
62
+ id
63
+ );
64
+ return generateIdmApi().put(urlString, data);
65
+ }
66
+
67
+ /**
68
+ * Query managed objects
69
+ * @param {String} type managed object type
70
+ * @param {[String]} fields fields to retrieve
71
+ * @param {String} pageCookie paged results cookie
72
+ * @returns {Promise} a promise that resolves to an object containing managed objects of the desired type
73
+ */
74
+ export async function queryAllManagedObjectsByType(type, fields, pageCookie) {
75
+ const fieldsParam =
76
+ fields.length > 0 ? `&_fields=${fields.join(',')}` : '&_fields=_id';
77
+ const urlTemplate = pageCookie
78
+ ? `${idmManagedObjectURLTemplate}${fieldsParam}&_pagedResultsCookie=${encodeURIComponent(
79
+ pageCookie
80
+ )}`
81
+ : `${idmManagedObjectURLTemplate}${fieldsParam}`;
82
+ const urlString = util.format(
83
+ urlTemplate,
84
+ getTenantURL(storage.session.getTenant()),
85
+ type
86
+ );
87
+ return generateIdmApi().get(urlString);
88
+ }
@@ -0,0 +1,45 @@
1
+ import util from 'util';
2
+ import { generateLogApi, generateLogKeysApi } from './BaseApi.js';
3
+ import { getTenantURL } from './utils/ApiUtils.js';
4
+ import storage from '../storage/SessionStorage.js';
5
+
6
+ const logsTailURLTemplate = '%s/monitoring/logs/tail?source=%s';
7
+ const logsSourcesURLTemplate = '%s/monitoring/logs/sources';
8
+ const logsCreateAPIKeyAndSecretURLTemplate = '%s/keys?_action=create';
9
+ const logsGetAPIKeysURLTemplate = '%s/keys';
10
+
11
+ export async function tail(source, cookie) {
12
+ let urlString = util.format(
13
+ logsTailURLTemplate,
14
+ getTenantURL(storage.session.getTenant()),
15
+ encodeURIComponent(source)
16
+ );
17
+ if (cookie) {
18
+ urlString += `&_pagedResultsCookie=${encodeURIComponent(cookie)}`;
19
+ }
20
+ return generateLogApi().get(urlString);
21
+ }
22
+
23
+ export async function getAPIKeys() {
24
+ const urlString = util.format(
25
+ logsGetAPIKeysURLTemplate,
26
+ getTenantURL(storage.session.getTenant())
27
+ );
28
+ return generateLogKeysApi().get(urlString);
29
+ }
30
+
31
+ export async function getSources() {
32
+ const urlString = util.format(
33
+ logsSourcesURLTemplate,
34
+ getTenantURL(storage.session.getTenant())
35
+ );
36
+ return generateLogApi().get(urlString);
37
+ }
38
+
39
+ export async function createAPIKeyAndSecret(keyName) {
40
+ const urlString = util.format(
41
+ logsCreateAPIKeyAndSecretURLTemplate,
42
+ getTenantURL(storage.session.getTenant())
43
+ );
44
+ return generateLogKeysApi().post(urlString, { name: keyName });
45
+ }
@@ -0,0 +1,62 @@
1
+ import util from 'util';
2
+ import { generateIdmApi } from './BaseApi.js';
3
+ import { getTenantURL } from './utils/ApiUtils.js';
4
+ import storage from '../storage/SessionStorage.js';
5
+
6
+ const managedObjectURLTemplate = '%s/openidm/managed/%s';
7
+ const managedObjectByIdURLTemplate = '%s/openidm/managed/%s/%s';
8
+ const managedObjectQueryAllURLTemplate = `${managedObjectURLTemplate}?_queryFilter=true&_pageSize=10000`;
9
+
10
+ /**
11
+ * Get managed object
12
+ * @param {String} id managed object id
13
+ * @returns {Promise} a promise that resolves to an object containing a managed object
14
+ */
15
+ export async function getManagedObject(type, id, fields) {
16
+ const fieldsParam =
17
+ fields.length > 0 ? `_fields=${fields.join(',')}` : '_fields=*';
18
+ const urlString = util.format(
19
+ `${managedObjectByIdURLTemplate}?${fieldsParam}`,
20
+ getTenantURL(storage.session.getTenant()),
21
+ type,
22
+ id
23
+ );
24
+ return generateIdmApi().get(urlString);
25
+ }
26
+
27
+ /**
28
+ * Put managed object
29
+ * @param {String} id managed object id
30
+ * @param {String} data managed object
31
+ * @returns {Promise} a promise that resolves to an object containing a managed object
32
+ */
33
+ export async function putManagedObject(type, id, data) {
34
+ const urlString = util.format(
35
+ managedObjectByIdURLTemplate,
36
+ getTenantURL(storage.session.getTenant()),
37
+ type,
38
+ id
39
+ );
40
+ return generateIdmApi().put(urlString, data);
41
+ }
42
+
43
+ /**
44
+ * Query managed objects
45
+ * @param {String} type managed object type
46
+ * @param {String} fields fields to retrieve
47
+ * @param {String} pageCookie paged results cookie
48
+ * @returns {Promise} a promise that resolves to an object containing managed objects of the desired type
49
+ */
50
+ export async function queryAllManagedObjectsByType(type, fields, pageCookie) {
51
+ const fieldsParam =
52
+ fields.length > 0 ? `&_fields=${fields.join(',')}` : '&_fields=_id';
53
+ const urlTemplate = pageCookie
54
+ ? `${managedObjectQueryAllURLTemplate}${fieldsParam}&_pagedResultsCookie=${pageCookie}`
55
+ : `${managedObjectQueryAllURLTemplate}${fieldsParam}`;
56
+ const urlString = util.format(
57
+ urlTemplate,
58
+ getTenantURL(storage.session.getTenant()),
59
+ type
60
+ );
61
+ return generateIdmApi().get(urlString);
62
+ }
@@ -0,0 +1,69 @@
1
+ import util from 'util';
2
+ import { generateAmApi } from './BaseApi.js';
3
+ import { getCurrentRealmPath } from './utils/ApiUtils.js';
4
+ import storage from '../storage/SessionStorage.js';
5
+
6
+ const oauth2ClientURLTemplate = '%s/json%s/realm-config/agents/OAuth2Client/%s';
7
+ const oauth2ClientListURLTemplate =
8
+ '%s/json%s/realm-config/agents/OAuth2Client?_queryFilter=true';
9
+ const apiVersion = 'protocol=2.1,resource=1.0';
10
+ const getApiConfig = () => {
11
+ const configPath = getCurrentRealmPath();
12
+ return {
13
+ path: `${configPath}/realm-config/agents/OAuth2Client`,
14
+ apiVersion,
15
+ };
16
+ };
17
+
18
+ /**
19
+ * Get OAuth2 Clients
20
+ * @returns {Promise} a promise that resolves to an object containing an array of oauth2client objects
21
+ */
22
+ export async function getOAuth2Clients() {
23
+ const urlString = util.format(
24
+ oauth2ClientListURLTemplate,
25
+ storage.session.getTenant(),
26
+ getCurrentRealmPath()
27
+ );
28
+ return generateAmApi(getApiConfig()).get(urlString, {
29
+ withCredentials: true,
30
+ });
31
+ }
32
+
33
+ /**
34
+ * Get OAuth2 Client
35
+ * @param {String} id client id
36
+ * @returns {Promise} a promise that resolves to an object containing an oauth2client object
37
+ */
38
+ export async function getOAuth2Client(id) {
39
+ const urlString = util.format(
40
+ oauth2ClientURLTemplate,
41
+ storage.session.getTenant(),
42
+ getCurrentRealmPath(),
43
+ id
44
+ );
45
+ return generateAmApi(getApiConfig()).get(urlString, {
46
+ withCredentials: true,
47
+ });
48
+ }
49
+
50
+ /**
51
+ * Put OAuth2 Client
52
+ * @param {String} id client id
53
+ * @param {Object} data oauth2client object
54
+ * @returns {Promise} a promise that resolves to an object containing an oauth2client object
55
+ */
56
+ export async function putOAuth2Client(id, data) {
57
+ const client = data;
58
+ delete client._provider;
59
+ delete client._rev;
60
+ const urlString = util.format(
61
+ oauth2ClientURLTemplate,
62
+ storage.session.getTenant(),
63
+ getCurrentRealmPath(storage.session.getRealm()),
64
+ id
65
+ );
66
+ return generateAmApi(getApiConfig()).put(urlString, client, {
67
+ withCredentials: true,
68
+ });
69
+ }
@@ -0,0 +1,73 @@
1
+ import util from 'util';
2
+ import qs from 'qs';
3
+ import { generateOauth2Api } from './BaseApi.js';
4
+ import { getCurrentRealmPath } from './utils/ApiUtils.js';
5
+ import storage from '../storage/SessionStorage.js';
6
+ import { encode } from './utils/Base64.js';
7
+
8
+ const authorizeUrlTemplate = '%s/oauth2%s/authorize';
9
+ const accessTokenUrlTemplate = '%s/oauth2%s/access_token';
10
+ const apiVersion = 'protocol=2.1,resource=1.0';
11
+ const getApiConfig = () => ({
12
+ apiVersion,
13
+ });
14
+
15
+ /**
16
+ * Perform the authorization step of the authorization code grant flow
17
+ * @param {String} data body form data
18
+ * @param {Object} config axios request config object
19
+ * @returns {Promise} a promise resolving to an object containing the authorization server response object
20
+ */
21
+ export async function authorize(data, config = {}) {
22
+ const authorizeURL = util.format(
23
+ authorizeUrlTemplate,
24
+ storage.session.getTenant(),
25
+ ''
26
+ );
27
+ return generateOauth2Api(getApiConfig()).post(authorizeURL, data, config);
28
+ }
29
+
30
+ /**
31
+ * Perform access token request step of the authorization code grant flow
32
+ * @param {*} data body form data
33
+ * @param {*} config config axios request config object
34
+ * @returns {Promise} a promise resolving to an object containing the authorization server response object containing the access token
35
+ */
36
+ export async function accessToken(data, config = {}) {
37
+ const accessTokenURL = util.format(
38
+ accessTokenUrlTemplate,
39
+ storage.session.getTenant(),
40
+ ''
41
+ );
42
+ return generateOauth2Api(getApiConfig()).post(accessTokenURL, data, config);
43
+ }
44
+
45
+ /**
46
+ * Perform client credentials grant flow
47
+ * @param {String} clientId client id
48
+ * @param {String} clientSecret client secret
49
+ * @param {String} scope space-delimited scope list
50
+ * @returns {Promise} a promise resolving to an object containing the authorization server response object
51
+ */
52
+ export async function clientCredentialsGrant(clientId, clientSecret, scope) {
53
+ const urlString = util.format(
54
+ accessTokenUrlTemplate,
55
+ storage.session.getTenant(),
56
+ getCurrentRealmPath()
57
+ );
58
+ const requestOverride = {
59
+ headers: {
60
+ Authorization: `Basic ${encode(`${clientId}:${clientSecret}`)}`,
61
+ 'Content-Type': 'application/x-www-form-urlencoded',
62
+ },
63
+ };
64
+ const requestBody = {
65
+ grant_type: 'client_credentials',
66
+ scope,
67
+ };
68
+ return generateOauth2Api(getApiConfig(), requestOverride).post(
69
+ urlString,
70
+ qs.stringify(requestBody),
71
+ { withCredentials: true }
72
+ );
73
+ }
@@ -0,0 +1,32 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import util from 'util';
3
+ import { generateAmApi } from './BaseApi.js';
4
+ import { getCurrentRealmPath } from './utils/ApiUtils.js';
5
+ import storage from '../storage/SessionStorage.js';
6
+
7
+ const oauthProviderServiceURLTemplate =
8
+ '%s/json%s/realm-config/services/oauth-oidc';
9
+
10
+ const apiVersion = 'protocol=2.1,resource=1.0';
11
+ const getApiConfig = () => {
12
+ const configPath = getCurrentRealmPath();
13
+ return {
14
+ path: `${configPath}/authentication/authenticationtrees`,
15
+ apiVersion,
16
+ };
17
+ };
18
+
19
+ /**
20
+ * Get OAuth2 Provider
21
+ * @returns {Promise} a promise that resolves to an object containing an OAuth2Provider object
22
+ */
23
+ export async function getOAuth2Provider() {
24
+ const urlString = util.format(
25
+ oauthProviderServiceURLTemplate,
26
+ storage.session.getTenant(),
27
+ getCurrentRealmPath()
28
+ );
29
+ return generateAmApi(getApiConfig()).get(urlString, {
30
+ withCredentials: true,
31
+ });
32
+ }
@@ -0,0 +1,99 @@
1
+ import util from 'util';
2
+ import {
3
+ getTenantURL,
4
+ getCurrentRealmPath,
5
+ getRealmName,
6
+ } from './utils/ApiUtils.js';
7
+ import { generateAmApi } from './BaseApi.js';
8
+ import storage from '../storage/SessionStorage.js';
9
+
10
+ const realmsListURLTemplate = '%s/json/global-config/realms/?_queryFilter=true';
11
+ const realmURLTemplate = '%s/json/global-config/realms/%s';
12
+
13
+ const apiVersion = 'protocol=2.0,resource=1.0';
14
+ const getApiConfig = () => {
15
+ const configPath = getCurrentRealmPath();
16
+ return {
17
+ path: `${configPath}/am/json/global-config/realms`,
18
+ apiVersion,
19
+ };
20
+ };
21
+
22
+ /**
23
+ * Get all realms
24
+ * @returns {Promise} a promise that resolves to an object containing an array of realm objects
25
+ */
26
+ export async function getRealms() {
27
+ const urlString = util.format(
28
+ realmsListURLTemplate,
29
+ storage.session.getTenant()
30
+ );
31
+ return generateAmApi(getApiConfig()).get(urlString, {
32
+ withCredentials: true,
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Get realm by id
38
+ * @param {String} id realm id
39
+ * @returns {Promise} a promise that resolves to an object containing a realm object
40
+ */
41
+ export async function getRealm(id) {
42
+ const urlString = util.format(
43
+ realmURLTemplate,
44
+ storage.session.getTenant(),
45
+ id
46
+ );
47
+ return generateAmApi(getApiConfig()).get(urlString, {
48
+ withCredentials: true,
49
+ });
50
+ }
51
+
52
+ /**
53
+ * Get realm by name
54
+ * @param {String} name realm name
55
+ * @returns {Promise} a promise that resolves to a realm object
56
+ */
57
+ export async function getRealmByName(name) {
58
+ return getRealms().then((realms) => {
59
+ for (const realm of realms.data.result) {
60
+ if (getRealmName(name) === realm.name) {
61
+ return realm;
62
+ }
63
+ }
64
+ throw new Error(`Realm ${name} not found!`);
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Put realm
70
+ * @param {String} id realm id
71
+ * @param {Object} data realm config object
72
+ * @returns {Promise} a promise that resolves to an object containing a realm object
73
+ */
74
+ export async function putRealm(id, data) {
75
+ const urlString = util.format(
76
+ realmURLTemplate,
77
+ storage.session.getTenant(),
78
+ id
79
+ );
80
+ return generateAmApi(getApiConfig()).put(urlString, data, {
81
+ withCredentials: true,
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Delete realm
87
+ * @param {String} id realm id
88
+ * @returns {Promise} a promise that resolves to an object containing a realm object
89
+ */
90
+ export async function deleteRealm(id) {
91
+ const urlString = util.format(
92
+ realmURLTemplate,
93
+ getTenantURL(storage.session.getTenant()),
94
+ id
95
+ );
96
+ return generateAmApi(getApiConfig()).delete(urlString, {
97
+ withCredentials: true,
98
+ });
99
+ }