@rockcarver/frodo-lib 0.16.2-9 → 0.17.1
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/CHANGELOG.md +222 -1
- package/cjs/api/AgentApi.js +14 -61
- package/cjs/api/AgentApi.js.map +1 -1
- package/cjs/api/AgentApi.test.js.map +1 -1
- package/cjs/api/ApiTypes.js +0 -5
- package/cjs/api/ApiTypes.js.map +1 -1
- package/cjs/api/AuthenticateApi.js +9 -20
- package/cjs/api/AuthenticateApi.js.map +1 -1
- package/cjs/api/AuthenticateApi.test.js.map +1 -0
- package/cjs/api/BaseApi.js +82 -124
- package/cjs/api/BaseApi.js.map +1 -1
- package/cjs/api/CirclesOfTrustApi.js +8 -32
- package/cjs/api/CirclesOfTrustApi.js.map +1 -1
- package/cjs/api/IdmConfigApi.js +9 -34
- package/cjs/api/IdmConfigApi.js.map +1 -1
- package/cjs/api/LogApi.js +8 -31
- package/cjs/api/LogApi.js.map +1 -1
- package/cjs/api/ManagedObjectApi.js +34 -31
- package/cjs/api/ManagedObjectApi.js.map +1 -1
- package/cjs/api/NodeApi.js +10 -41
- package/cjs/api/NodeApi.js.map +1 -1
- package/cjs/api/NodeApi.test.js.map +1 -1
- package/cjs/api/OAuth2ClientApi.js +7 -26
- package/cjs/api/OAuth2ClientApi.js.map +1 -1
- package/cjs/api/OAuth2OIDCApi.js +28 -34
- package/cjs/api/OAuth2OIDCApi.js.map +1 -1
- package/cjs/api/OAuth2OIDCApi.test.js.map +1 -0
- package/cjs/api/OAuth2ProviderApi.js +5 -15
- package/cjs/api/OAuth2ProviderApi.js.map +1 -1
- package/cjs/api/RealmApi.js +8 -34
- package/cjs/api/RealmApi.js.map +1 -1
- package/cjs/api/Saml2Api.js +16 -67
- package/cjs/api/Saml2Api.js.map +1 -1
- package/cjs/api/ScriptApi.js +8 -30
- package/cjs/api/ScriptApi.js.map +1 -1
- package/cjs/api/SecretsApi.js +14 -64
- package/cjs/api/SecretsApi.js.map +1 -1
- package/cjs/api/SecretsApi.test.js.map +1 -1
- package/cjs/api/ServerInfoApi.js +6 -21
- package/cjs/api/ServerInfoApi.js.map +1 -1
- package/cjs/api/ServiceApi.js +49 -47
- package/cjs/api/ServiceApi.js.map +1 -1
- package/cjs/api/SocialIdentityProvidersApi.js +9 -36
- package/cjs/api/SocialIdentityProvidersApi.js.map +1 -1
- package/cjs/api/StartupApi.js +5 -24
- package/cjs/api/StartupApi.js.map +1 -1
- package/cjs/api/StartupApi.test.js.map +1 -1
- package/cjs/api/TreeApi.js +8 -30
- package/cjs/api/TreeApi.js.map +1 -1
- package/cjs/api/TreeApi.test.js.map +1 -1
- package/cjs/api/VariablesApi.js +9 -37
- package/cjs/api/VariablesApi.js.map +1 -1
- package/cjs/api/VariablesApi.test.js.map +1 -1
- package/cjs/api/utils/ApiUtils.js +47 -57
- package/cjs/api/utils/ApiUtils.js.map +1 -1
- package/cjs/api/utils/ApiUtils.test.js.map +1 -1
- package/cjs/api/utils/Base64.js +5 -15
- package/cjs/api/utils/Base64.js.map +1 -1
- package/cjs/ext/axios-curlirize/curlirize.js +2 -9
- package/cjs/ext/axios-curlirize/curlirize.js.map +1 -1
- package/cjs/ext/axios-curlirize/lib/CurlHelper.js +7 -22
- package/cjs/ext/axios-curlirize/lib/CurlHelper.js.map +1 -1
- package/cjs/index.js +30 -89
- package/cjs/index.js.map +1 -1
- package/cjs/ops/AdminOps.js +27 -165
- package/cjs/ops/AdminOps.js.map +1 -1
- package/cjs/ops/AgentOps.js +2 -159
- package/cjs/ops/AgentOps.js.map +1 -1
- package/cjs/ops/AgentOps.test.js.map +1 -1
- package/cjs/ops/AuthenticateOps.js +266 -226
- package/cjs/ops/AuthenticateOps.js.map +1 -1
- package/cjs/ops/AuthenticateOps.test.js.map +1 -1
- package/cjs/ops/CirclesOfTrustOps.js +13 -91
- package/cjs/ops/CirclesOfTrustOps.js.map +1 -1
- package/cjs/ops/ConnectionProfileOps.js +220 -136
- package/cjs/ops/ConnectionProfileOps.js.map +1 -1
- package/cjs/ops/ConnectionProfileOps.test.js.map +1 -1
- package/cjs/ops/EmailTemplateOps.js +35 -379
- package/cjs/ops/EmailTemplateOps.js.map +1 -1
- package/cjs/ops/EmailTemplateOps.test.js.map +1 -1
- package/cjs/ops/IdmOps.js +52 -426
- package/cjs/ops/IdmOps.js.map +1 -1
- package/cjs/ops/IdmOps.test.js.map +1 -1
- package/cjs/ops/IdpOps.js +11 -94
- package/cjs/ops/IdpOps.js.map +1 -1
- package/cjs/ops/IdpOps.test.js.map +1 -1
- package/cjs/ops/JoseOps.js +81 -0
- package/cjs/ops/JoseOps.js.map +1 -0
- package/cjs/ops/JoseOps.test.js.map +1 -0
- package/cjs/ops/JourneyOps.js +139 -370
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/JourneyOps.test.js.map +1 -1
- package/cjs/ops/LogOps.js +14 -47
- package/cjs/ops/LogOps.js.map +1 -1
- package/cjs/ops/ManagedObjectOps.js +4 -12
- package/cjs/ops/ManagedObjectOps.js.map +1 -1
- package/cjs/ops/NodeOps.js +9 -67
- package/cjs/ops/NodeOps.js.map +1 -1
- package/cjs/ops/OAuth2ClientOps.js +10 -40
- package/cjs/ops/OAuth2ClientOps.js.map +1 -1
- package/cjs/ops/OpsTypes.js +0 -5
- package/cjs/ops/OpsTypes.js.map +1 -1
- package/cjs/ops/OrganizationOps.js +6 -25
- package/cjs/ops/OrganizationOps.js.map +1 -1
- package/cjs/ops/RealmOps.js +0 -19
- package/cjs/ops/RealmOps.js.map +1 -1
- package/cjs/ops/Saml2Ops.js +11 -107
- package/cjs/ops/Saml2Ops.js.map +1 -1
- package/cjs/ops/Saml2Ops.test.js.map +1 -1
- package/cjs/ops/ScriptOps.js +26 -73
- package/cjs/ops/ScriptOps.js.map +1 -1
- package/cjs/ops/SecretsOps.js +2 -58
- package/cjs/ops/SecretsOps.js.map +1 -1
- package/cjs/ops/ServiceAccountOps.js +61 -0
- package/cjs/ops/ServiceAccountOps.js.map +1 -0
- package/cjs/ops/ServiceAccountOps.test.js.map +1 -0
- package/cjs/ops/ServiceOps.js +55 -101
- package/cjs/ops/ServiceOps.js.map +1 -1
- package/cjs/ops/StartupOps.js +2 -23
- package/cjs/ops/StartupOps.js.map +1 -1
- package/cjs/ops/ThemeOps.js +230 -436
- package/cjs/ops/ThemeOps.js.map +1 -1
- package/cjs/ops/ThemeOps.test.js.map +1 -0
- package/cjs/ops/VariablesOps.js +0 -38
- package/cjs/ops/VariablesOps.js.map +1 -1
- package/cjs/ops/utils/Console.js +29 -62
- package/cjs/ops/utils/Console.js.map +1 -1
- package/cjs/ops/utils/DataProtection.js +13 -47
- package/cjs/ops/utils/DataProtection.js.map +1 -1
- package/cjs/ops/utils/DataProtection.test.js.map +1 -1
- package/cjs/ops/utils/ExportImportUtils.js +36 -74
- package/cjs/ops/utils/ExportImportUtils.js.map +1 -1
- package/cjs/ops/utils/ExportImportUtils.test.js.map +1 -1
- package/cjs/ops/utils/OpsUtils.js +27 -43
- package/cjs/ops/utils/OpsUtils.js.map +1 -1
- package/cjs/ops/utils/OpsUtils.test.js.map +1 -1
- package/cjs/ops/utils/ValidationUtils.js +0 -13
- package/cjs/ops/utils/ValidationUtils.js.map +1 -1
- package/cjs/ops/utils/ValidationUtils.test.js.map +1 -1
- package/cjs/ops/utils/Version.js +2 -12
- package/cjs/ops/utils/Version.js.map +1 -1
- package/cjs/ops/utils/Version.test.js.map +1 -1
- package/cjs/ops/utils/Wordwrap.js +1 -2
- package/cjs/ops/utils/Wordwrap.js.map +1 -1
- package/cjs/ops/utils/Wordwrap.test.js.map +1 -0
- package/cjs/shared/State.js +239 -0
- package/cjs/shared/State.js.map +1 -0
- package/cjs/shared/State.test.js.map +1 -0
- package/cjs/storage/StaticStorage.js.map +1 -1
- package/cjs/test/mocks/AuthenticateApi/step/default_steps.json +88 -0
- package/cjs/test/mocks/ForgeRockApiMockEngine.js +161 -83
- package/cjs/test/mocks/ForgeRockApiMockEngine.js.map +1 -1
- package/cjs/test/mocks/IdmConfigApi/getConfigEntity/managed.json +4420 -0
- package/cjs/test/mocks/OAuth2OIDCApi/accessToken/body.json +6 -0
- package/cjs/test/mocks/OAuth2OIDCApi/accessToken/headers.json +19 -0
- package/cjs/test/mocks/OAuth2OIDCApi/authorize/headers.json +38 -0
- package/cjs/test/mocks/ServerInfoApi/getServerInfo/info.json +25 -0
- package/cjs/test/mocks/ServerInfoApi/getServerVersionInfo/version.json +8 -0
- package/cjs/utils/AutoSetupPolly.js +79 -0
- package/cjs/utils/AutoSetupPolly.js.map +1 -0
- package/cjs/utils/SetupJest.js +6 -0
- package/cjs/utils/SetupJest.js.map +1 -0
- package/cjs/{test/mocks → utils}/snapshotResolve.js +10 -12
- package/cjs/utils/snapshotResolve.js.map +1 -0
- package/esm/api/AgentApi.mjs +19 -21
- package/esm/api/AgentApi.test.mjs +6 -15
- package/esm/api/ApiTypes.mjs +0 -5
- package/esm/api/AuthenticateApi.mjs +7 -10
- package/esm/api/AuthenticateApi.test.mjs +39 -0
- package/esm/api/BaseApi.mjs +96 -81
- package/esm/api/CirclesOfTrustApi.mjs +9 -12
- package/esm/api/IdmConfigApi.mjs +11 -12
- package/esm/api/LogApi.mjs +6 -10
- package/esm/api/ManagedObjectApi.mjs +23 -8
- package/esm/api/NodeApi.mjs +13 -15
- package/esm/api/NodeApi.test.mjs +13 -17
- package/esm/api/OAuth2ClientApi.mjs +7 -9
- package/esm/api/OAuth2OIDCApi.mjs +15 -9
- package/esm/api/OAuth2OIDCApi.test.mjs +53 -0
- package/esm/api/OAuth2ProviderApi.mjs +3 -5
- package/esm/api/RealmApi.mjs +10 -13
- package/esm/api/Saml2Api.mjs +25 -29
- package/esm/api/ScriptApi.mjs +9 -11
- package/esm/api/SecretsApi.mjs +21 -24
- package/esm/api/SecretsApi.test.mjs +9 -31
- package/esm/api/ServerInfoApi.mjs +5 -9
- package/esm/api/ServiceApi.mjs +53 -26
- package/esm/api/SocialIdentityProvidersApi.mjs +11 -13
- package/esm/api/StartupApi.mjs +5 -10
- package/esm/api/StartupApi.test.mjs +4 -7
- package/esm/api/TreeApi.mjs +9 -11
- package/esm/api/TreeApi.test.mjs +24 -61
- package/esm/api/VariablesApi.mjs +11 -13
- package/esm/api/VariablesApi.test.mjs +80 -222
- package/esm/api/utils/ApiUtils.mjs +45 -48
- package/esm/api/utils/ApiUtils.test.mjs +33 -32
- package/esm/api/utils/Base64.mjs +5 -9
- package/esm/ext/axios-curlirize/curlirize.mjs +2 -7
- package/esm/ext/axios-curlirize/lib/CurlHelper.mjs +7 -20
- package/esm/index.mjs +23 -13
- package/esm/ops/AdminOps.mjs +33 -119
- package/esm/ops/AgentOps.mjs +37 -80
- package/esm/ops/AgentOps.test.mjs +5 -45
- package/esm/ops/AuthenticateOps.mjs +242 -175
- package/esm/ops/AuthenticateOps.test.mjs +7 -9
- package/esm/ops/CirclesOfTrustOps.mjs +24 -61
- package/esm/ops/ConnectionProfileOps.mjs +192 -82
- package/esm/ops/ConnectionProfileOps.test.mjs +19 -19
- package/esm/ops/EmailTemplateOps.mjs +18 -276
- package/esm/ops/EmailTemplateOps.test.mjs +19 -44
- package/esm/ops/IdmOps.mjs +30 -327
- package/esm/ops/IdmOps.test.mjs +47 -54
- package/esm/ops/IdpOps.mjs +21 -59
- package/esm/ops/IdpOps.test.mjs +5 -5
- package/esm/ops/JoseOps.mjs +41 -0
- package/esm/ops/JoseOps.test.mjs +137 -0
- package/esm/ops/JourneyOps.mjs +146 -289
- package/esm/ops/JourneyOps.test.mjs +29 -27
- package/esm/ops/LogOps.mjs +15 -25
- package/esm/ops/ManagedObjectOps.mjs +6 -6
- package/esm/ops/NodeOps.mjs +9 -47
- package/esm/ops/OAuth2ClientOps.mjs +13 -19
- package/esm/ops/OpsTypes.mjs +1 -3
- package/esm/ops/OrganizationOps.mjs +7 -14
- package/esm/ops/RealmOps.mjs +4 -7
- package/esm/ops/Saml2Ops.mjs +28 -62
- package/esm/ops/Saml2Ops.test.mjs +20 -23
- package/esm/ops/ScriptOps.mjs +29 -47
- package/esm/ops/SecretsOps.mjs +15 -31
- package/esm/ops/ServiceAccountOps.mjs +41 -0
- package/esm/ops/ServiceAccountOps.test.mjs +51 -0
- package/esm/ops/ServiceOps.mjs +66 -83
- package/esm/ops/StartupOps.mjs +4 -13
- package/esm/ops/ThemeOps.mjs +189 -298
- package/esm/{api/ThemeApi.test.mjs → ops/ThemeOps.test.mjs} +91 -96
- package/esm/ops/VariablesOps.mjs +9 -18
- package/esm/ops/utils/Console.mjs +28 -46
- package/esm/ops/utils/DataProtection.mjs +15 -28
- package/esm/ops/utils/DataProtection.test.mjs +8 -8
- package/esm/ops/utils/ExportImportUtils.mjs +34 -43
- package/esm/ops/utils/ExportImportUtils.test.mjs +20 -18
- package/esm/ops/utils/OpsUtils.mjs +27 -21
- package/esm/ops/utils/OpsUtils.test.mjs +155 -27
- package/esm/ops/utils/ValidationUtils.mjs +0 -9
- package/esm/ops/utils/Version.mjs +2 -3
- package/esm/ops/utils/Version.test.mjs +0 -2
- package/esm/ops/utils/Wordwrap.mjs +1 -1
- package/esm/ops/utils/Wordwrap.test.mjs +19 -0
- package/esm/shared/State.mjs +164 -0
- package/esm/shared/State.test.mjs +249 -0
- package/esm/test/mocks/AuthenticateApi/step/default_steps.json +88 -0
- package/esm/test/mocks/ForgeRockApiMockEngine.mjs +147 -31
- package/esm/test/mocks/IdmConfigApi/getConfigEntity/managed.json +4420 -0
- package/esm/test/mocks/OAuth2OIDCApi/accessToken/body.json +6 -0
- package/esm/test/mocks/OAuth2OIDCApi/accessToken/headers.json +19 -0
- package/esm/test/mocks/OAuth2OIDCApi/authorize/headers.json +38 -0
- package/esm/test/mocks/ServerInfoApi/getServerInfo/info.json +25 -0
- package/esm/test/mocks/ServerInfoApi/getServerVersionInfo/version.json +8 -0
- package/esm/utils/AutoSetupPolly.mjs +72 -0
- package/esm/utils/SetupJest.mjs +3 -0
- package/esm/{test/mocks → utils}/snapshotResolve.mjs +10 -12
- package/package.json +36 -26
- package/types/api/AgentApi.d.ts.map +1 -1
- package/types/api/ApiTypes.d.ts +15 -16
- package/types/api/ApiTypes.d.ts.map +1 -1
- package/types/api/AuthenticateApi.d.ts +1 -1
- package/types/api/AuthenticateApi.d.ts.map +1 -1
- package/types/api/BaseApi.d.ts +2 -0
- package/types/api/BaseApi.d.ts.map +1 -1
- package/types/api/CirclesOfTrustApi.d.ts.map +1 -1
- package/types/api/IdmConfigApi.d.ts.map +1 -1
- package/types/api/LogApi.d.ts.map +1 -1
- package/types/api/ManagedObjectApi.d.ts +9 -1
- package/types/api/ManagedObjectApi.d.ts.map +1 -1
- package/types/api/NodeApi.d.ts.map +1 -1
- package/types/api/OAuth2ClientApi.d.ts.map +1 -1
- package/types/api/OAuth2OIDCApi.d.ts +4 -2
- package/types/api/OAuth2OIDCApi.d.ts.map +1 -1
- package/types/api/OAuth2ProviderApi.d.ts.map +1 -1
- package/types/api/RealmApi.d.ts.map +1 -1
- package/types/api/Saml2Api.d.ts.map +1 -1
- package/types/api/ScriptApi.d.ts.map +1 -1
- package/types/api/SecretsApi.d.ts.map +1 -1
- package/types/api/ServerInfoApi.d.ts.map +1 -1
- package/types/api/ServiceApi.d.ts +14 -7
- package/types/api/ServiceApi.d.ts.map +1 -1
- package/types/api/SocialIdentityProvidersApi.d.ts.map +1 -1
- package/types/api/StartupApi.d.ts.map +1 -1
- package/types/api/TreeApi.d.ts.map +1 -1
- package/types/api/VariablesApi.d.ts.map +1 -1
- package/types/api/utils/ApiUtils.d.ts +1 -0
- package/types/api/utils/ApiUtils.d.ts.map +1 -1
- package/types/index.d.ts +11 -5
- package/types/index.d.ts.map +1 -1
- package/types/ops/AuthenticateOps.d.ts +10 -2
- package/types/ops/AuthenticateOps.d.ts.map +1 -1
- package/types/ops/ConnectionProfileOps.d.ts +49 -21
- package/types/ops/ConnectionProfileOps.d.ts.map +1 -1
- package/types/ops/EmailTemplateOps.d.ts +14 -33
- package/types/ops/EmailTemplateOps.d.ts.map +1 -1
- package/types/ops/IdmOps.d.ts +29 -37
- package/types/ops/IdmOps.d.ts.map +1 -1
- package/types/ops/JoseOps.d.ts +33 -0
- package/types/ops/JoseOps.d.ts.map +1 -0
- package/types/ops/JourneyOps.d.ts.map +1 -1
- package/types/ops/LogOps.d.ts.map +1 -1
- package/types/ops/NodeOps.d.ts.map +1 -1
- package/types/ops/OAuth2ClientOps.d.ts.map +1 -1
- package/types/ops/OpsTypes.d.ts +1 -1
- package/types/ops/OpsTypes.d.ts.map +1 -1
- package/types/ops/OrganizationOps.d.ts.map +1 -1
- package/types/ops/ScriptOps.d.ts.map +1 -1
- package/types/ops/ServiceAccountOps.d.ts +20 -0
- package/types/ops/ServiceAccountOps.d.ts.map +1 -0
- package/types/ops/ServiceOps.d.ts +18 -10
- package/types/ops/ServiceOps.d.ts.map +1 -1
- package/types/ops/ThemeOps.d.ts +35 -50
- package/types/ops/ThemeOps.d.ts.map +1 -1
- package/types/ops/utils/Console.d.ts +1 -1
- package/types/ops/utils/Console.d.ts.map +1 -1
- package/types/ops/utils/DataProtection.d.ts.map +1 -1
- package/types/ops/utils/ExportImportUtils.d.ts +5 -2
- package/types/ops/utils/ExportImportUtils.d.ts.map +1 -1
- package/types/ops/utils/OpsUtils.d.ts +6 -0
- package/types/ops/utils/OpsUtils.d.ts.map +1 -1
- package/types/ops/utils/Wordwrap.d.ts.map +1 -1
- package/types/shared/State.d.ts +223 -0
- package/types/shared/State.d.ts.map +1 -0
- package/types/test/mocks/ForgeRockApiMockEngine.d.ts +19 -1
- package/types/test/mocks/ForgeRockApiMockEngine.d.ts.map +1 -1
- package/types/utils/AutoSetupPolly.d.ts +1 -0
- package/types/utils/AutoSetupPolly.d.ts.map +1 -0
- package/types/utils/SetupJest.d.ts +1 -0
- package/types/utils/SetupJest.d.ts.map +1 -0
- package/types/utils/snapshotResolve.d.ts +1 -0
- package/types/utils/snapshotResolve.d.ts.map +1 -0
- package/cjs/api/EmailTemplateApi.js +0 -73
- package/cjs/api/EmailTemplateApi.js.map +0 -1
- package/cjs/api/ThemeApi.js +0 -367
- package/cjs/api/ThemeApi.js.map +0 -1
- package/cjs/api/ThemeApi.test.js.map +0 -1
- package/cjs/storage/SessionStorage.js +0 -91
- package/cjs/storage/SessionStorage.js.map +0 -1
- package/cjs/test/mocks/snapshotResolve.js.map +0 -1
- package/esm/api/EmailTemplateApi.mjs +0 -34
- package/esm/api/ThemeApi.mjs +0 -271
- package/esm/storage/SessionStorage.mjs +0 -79
- package/types/api/EmailTemplateApi.d.ts +0 -22
- package/types/api/EmailTemplateApi.d.ts.map +0 -1
- package/types/api/ThemeApi.d.ts +0 -56
- package/types/api/ThemeApi.d.ts.map +0 -1
- package/types/storage/SessionStorage.d.ts +0 -71
- package/types/storage/SessionStorage.d.ts.map +0 -1
- package/types/test/mocks/snapshotResolve.d.ts +0 -1
- package/types/test/mocks/snapshotResolve.d.ts.map +0 -1
|
@@ -2,37 +2,46 @@ import url from 'url';
|
|
|
2
2
|
import { createHash, randomBytes } from 'crypto';
|
|
3
3
|
import readlineSync from 'readline-sync';
|
|
4
4
|
import { encodeBase64Url } from '../api/utils/Base64';
|
|
5
|
-
import
|
|
5
|
+
import * as state from '../shared/State';
|
|
6
6
|
import * as globalConfig from '../storage/StaticStorage';
|
|
7
|
-
import { printMessage } from './utils/Console';
|
|
7
|
+
import { debugMessage, printMessage, verboseMessage } from './utils/Console';
|
|
8
8
|
import { getServerInfo, getServerVersionInfo } from '../api/ServerInfoApi';
|
|
9
9
|
import { step } from '../api/AuthenticateApi';
|
|
10
10
|
import { accessToken, authorize } from '../api/OAuth2OIDCApi';
|
|
11
|
-
import { getConnectionProfile
|
|
11
|
+
import { getConnectionProfile } from './ConnectionProfileOps';
|
|
12
|
+
import { v4 } from 'uuid';
|
|
13
|
+
import { parseUrl } from '../api/utils/ApiUtils';
|
|
14
|
+
import { createSignedJwtToken } from './JoseOps';
|
|
15
|
+
import { getManagedObject } from '../api/ManagedObjectApi';
|
|
12
16
|
const adminClientPassword = 'doesnotmatter';
|
|
13
17
|
const redirectUrlTemplate = '/platform/appAuthHelperRedirect.html';
|
|
14
|
-
const
|
|
18
|
+
const idmAdminScopes = 'fr:idm:* openid';
|
|
19
|
+
const serviceAccountScopes = 'fr:am:* fr:idm:* fr:idc:esv:*';
|
|
15
20
|
let adminClientId = 'idmAdminClient';
|
|
21
|
+
|
|
16
22
|
/**
|
|
17
23
|
* Helper function to get cookie name
|
|
18
24
|
* @returns {String} cookie name
|
|
19
25
|
*/
|
|
20
|
-
|
|
21
|
-
async function getCookieName() {
|
|
26
|
+
async function determineCookieName() {
|
|
22
27
|
try {
|
|
23
|
-
|
|
28
|
+
const {
|
|
29
|
+
data
|
|
30
|
+
} = await getServerInfo();
|
|
31
|
+
debugMessage(`AuthenticateOps.getCookieName: cookieName=${data.cookieName}`);
|
|
32
|
+
return data.cookieName;
|
|
24
33
|
} catch (error) {
|
|
25
34
|
printMessage(`Error getting cookie name: ${error}`, 'error');
|
|
35
|
+
debugMessage(error.stack);
|
|
26
36
|
return null;
|
|
27
37
|
}
|
|
28
38
|
}
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
* Helper function to determine if this is a setup mfa prompt in the ID Cloud tenant admin login journey
|
|
31
42
|
* @param {Object} payload response from the previous authentication journey step
|
|
32
43
|
* @returns {Object} an object indicating if 2fa is required and the original payload
|
|
33
44
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
45
|
function checkAndHandle2FA(payload) {
|
|
37
46
|
// let skippable = false;
|
|
38
47
|
if ('callbacks' in payload) {
|
|
@@ -47,7 +56,6 @@ function checkAndHandle2FA(payload) {
|
|
|
47
56
|
};
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
|
-
|
|
51
59
|
if (element.type === 'NameCallback') {
|
|
52
60
|
if (element.output[0].value.includes('code')) {
|
|
53
61
|
// skippable = false;
|
|
@@ -60,89 +68,92 @@ function checkAndHandle2FA(payload) {
|
|
|
60
68
|
};
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
}
|
|
72
|
+
// console.info("NO2FA");
|
|
66
73
|
return {
|
|
67
74
|
need2fa: false,
|
|
68
75
|
payload
|
|
69
76
|
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
}
|
|
78
|
+
// console.info("NO2FA");
|
|
73
79
|
return {
|
|
74
80
|
need2fa: false,
|
|
75
81
|
payload
|
|
76
82
|
};
|
|
77
83
|
}
|
|
84
|
+
|
|
78
85
|
/**
|
|
79
86
|
* Helper function to set the default realm by deployment type
|
|
80
|
-
* @param {
|
|
87
|
+
* @param {string} deploymentType deployment type
|
|
81
88
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
89
|
function determineDefaultRealm(deploymentType) {
|
|
85
|
-
if (
|
|
86
|
-
|
|
90
|
+
if (!state.getRealm() || state.getRealm() === globalConfig.DEFAULT_REALM_KEY) {
|
|
91
|
+
state.setRealm(globalConfig.DEPLOYMENT_TYPE_REALM_MAP[deploymentType]);
|
|
87
92
|
}
|
|
88
93
|
}
|
|
94
|
+
|
|
89
95
|
/**
|
|
90
96
|
* Helper function to determine the deployment type
|
|
91
|
-
* @returns {
|
|
97
|
+
* @returns {Promise<string>} deployment type
|
|
92
98
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
99
|
async function determineDeploymentType() {
|
|
100
|
+
const cookieValue = state.getCookieValue();
|
|
101
|
+
// https://bugster.forgerock.org/jira/browse/FRAAS-13018
|
|
102
|
+
// There is a chance that this will be blocked due to security concerns and thus is probably best not to keep active
|
|
103
|
+
// if (!cookieValue && getUseBearerTokenForAmApis()) {
|
|
104
|
+
// const token = await getTokenInfo();
|
|
105
|
+
// cookieValue = token.sessionToken;
|
|
106
|
+
// setCookieValue(cookieValue);
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
// if we are using a service account, we know it's cloud
|
|
110
|
+
if (state.getUseBearerTokenForAmApis()) return globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY;
|
|
96
111
|
const fidcClientId = 'idmAdminClient';
|
|
97
112
|
const forgeopsClientId = 'idm-admin-ui';
|
|
98
113
|
const verifier = encodeBase64Url(randomBytes(32));
|
|
99
114
|
const challenge = encodeBase64Url(createHash('sha256').update(verifier).digest());
|
|
100
115
|
const challengeMethod = 'S256';
|
|
101
|
-
const redirectURL = url.resolve(
|
|
116
|
+
const redirectURL = url.resolve(state.getHost(), redirectUrlTemplate);
|
|
102
117
|
const config = {
|
|
103
|
-
maxRedirects: 0
|
|
118
|
+
maxRedirects: 0,
|
|
119
|
+
headers: {
|
|
120
|
+
[state.getCookieName()]: state.getCookieValue()
|
|
121
|
+
}
|
|
104
122
|
};
|
|
105
|
-
let bodyFormData = `redirect_uri=${redirectURL}&scope=${
|
|
123
|
+
let bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScopes}&response_type=code&client_id=${fidcClientId}&csrf=${cookieValue}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;
|
|
106
124
|
let deploymentType = globalConfig.CLASSIC_DEPLOYMENT_TYPE_KEY;
|
|
107
|
-
|
|
108
125
|
try {
|
|
109
126
|
await authorize(bodyFormData, config);
|
|
110
127
|
} catch (e) {
|
|
111
128
|
var _e$response, _e$response$headers, _e$response$headers$l;
|
|
112
|
-
|
|
129
|
+
// debugMessage(e.response);
|
|
113
130
|
if (((_e$response = e.response) === null || _e$response === void 0 ? void 0 : _e$response.status) === 302 && ((_e$response$headers = e.response.headers) === null || _e$response$headers === void 0 ? void 0 : (_e$response$headers$l = _e$response$headers.location) === null || _e$response$headers$l === void 0 ? void 0 : _e$response$headers$l.indexOf('code=')) > -1) {
|
|
114
|
-
|
|
131
|
+
verboseMessage(`ForgeRock Identity Cloud`['brightCyan'] + ` detected.`);
|
|
115
132
|
deploymentType = globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY;
|
|
116
133
|
} else {
|
|
117
134
|
try {
|
|
118
|
-
bodyFormData = `redirect_uri=${redirectURL}&scope=${
|
|
135
|
+
bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScopes}&response_type=code&client_id=${forgeopsClientId}&csrf=${state.getCookieValue()}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;
|
|
119
136
|
await authorize(bodyFormData, config);
|
|
120
137
|
} catch (ex) {
|
|
121
138
|
var _ex$response, _ex$response$headers, _ex$response$headers$;
|
|
122
|
-
|
|
123
139
|
if (((_ex$response = ex.response) === null || _ex$response === void 0 ? void 0 : _ex$response.status) === 302 && ((_ex$response$headers = ex.response.headers) === null || _ex$response$headers === void 0 ? void 0 : (_ex$response$headers$ = _ex$response$headers.location) === null || _ex$response$headers$ === void 0 ? void 0 : _ex$response$headers$.indexOf('code=')) > -1) {
|
|
124
140
|
adminClientId = forgeopsClientId;
|
|
125
|
-
|
|
141
|
+
verboseMessage(`ForgeOps deployment`['brightCyan'] + ` detected.`);
|
|
126
142
|
deploymentType = globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY;
|
|
127
143
|
} else {
|
|
128
|
-
|
|
144
|
+
verboseMessage(`Classic deployment`['brightCyan'] + ` detected.`);
|
|
129
145
|
}
|
|
130
146
|
}
|
|
131
147
|
}
|
|
132
|
-
|
|
133
|
-
printMessage('detected.');
|
|
134
148
|
}
|
|
135
|
-
|
|
136
|
-
determineDefaultRealm(deploymentType);
|
|
137
149
|
return deploymentType;
|
|
138
150
|
}
|
|
151
|
+
|
|
139
152
|
/**
|
|
140
153
|
* Helper function to extract the semantic version string from a version info object
|
|
141
154
|
* @param {Object} versionInfo version info object
|
|
142
155
|
* @returns {String} semantic version
|
|
143
156
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
157
|
async function getSemanticVersion(versionInfo) {
|
|
147
158
|
if ('version' in versionInfo) {
|
|
148
159
|
const versionString = versionInfo.version;
|
|
@@ -150,140 +161,95 @@ async function getSemanticVersion(versionInfo) {
|
|
|
150
161
|
const version = versionString.match(rx);
|
|
151
162
|
return version[0];
|
|
152
163
|
}
|
|
153
|
-
|
|
154
164
|
throw new Error('Cannot extract semantic version from version info object.');
|
|
155
165
|
}
|
|
166
|
+
|
|
156
167
|
/**
|
|
157
168
|
* Helper function to authenticate and obtain and store session cookie
|
|
158
|
-
* @returns {
|
|
169
|
+
* @returns {string} Session token or null
|
|
159
170
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
try {
|
|
166
|
-
const config = {
|
|
167
|
-
headers: {
|
|
168
|
-
'X-OpenAM-Username': storage.session.getUsername(),
|
|
169
|
-
'X-OpenAM-Password': storage.session.getPassword()
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
const response1 = (await step({}, config)).data;
|
|
173
|
-
const skip2FA = checkAndHandle2FA(response1);
|
|
174
|
-
let response2 = {};
|
|
175
|
-
|
|
176
|
-
if (skip2FA.need2fa) {
|
|
177
|
-
response2 = (await step(skip2FA.payload)).data;
|
|
178
|
-
} else {
|
|
179
|
-
response2 = skip2FA.payload;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if ('tokenId' in response2) {
|
|
183
|
-
storage.session.setCookieValue(response2['tokenId']);
|
|
184
|
-
|
|
185
|
-
if (!storage.session.getDeploymentType()) {
|
|
186
|
-
storage.session.setDeploymentType(await determineDeploymentType());
|
|
187
|
-
} else {
|
|
188
|
-
determineDefaultRealm(storage.session.getDeploymentType());
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const versionInfo = (await getServerVersionInfo()).data; // https://github.com/rockcarver/frodo-cli/issues/109
|
|
192
|
-
// printMessage(`Connected to ${versionInfo.fullVersion}`);
|
|
193
|
-
// https://github.com/rockcarver/frodo-cli/issues/102
|
|
194
|
-
|
|
195
|
-
printMessage(`Connected to [${storage.session.getTenant()}], [${!storage.session.getRealm() ? 'alpha' : storage.session.getRealm()}] realm, as [${storage.session.getUsername()}]`);
|
|
196
|
-
const version = await getSemanticVersion(versionInfo);
|
|
197
|
-
storage.session.setAmVersion(version);
|
|
198
|
-
return '';
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
printMessage(`error authenticating`, 'error');
|
|
202
|
-
printMessage('+++ likely cause, bad credentials!!! +++', 'error');
|
|
203
|
-
return null;
|
|
204
|
-
} catch (e) {
|
|
205
|
-
var _e$response2;
|
|
206
|
-
|
|
207
|
-
if (((_e$response2 = e.response) === null || _e$response2 === void 0 ? void 0 : _e$response2.status) === 401) {
|
|
208
|
-
printMessage(`error authenticating - ${e.message}`, 'error');
|
|
209
|
-
printMessage('+++ likely cause, bad credentials +++', 'error');
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (e.message === 'self signed certificate') {
|
|
213
|
-
printMessage(`error authenticating - ${e.message}`, 'error');
|
|
214
|
-
printMessage('+++ use -k, --insecure option to allow +++', 'error');
|
|
215
|
-
} else {
|
|
216
|
-
var _e$response3;
|
|
217
|
-
|
|
218
|
-
printMessage(`error authenticating - ${e.message}`, 'error');
|
|
219
|
-
printMessage((_e$response3 = e.response) === null || _e$response3 === void 0 ? void 0 : _e$response3.data, 'error');
|
|
171
|
+
async function authenticate(username, password) {
|
|
172
|
+
const config = {
|
|
173
|
+
headers: {
|
|
174
|
+
'X-OpenAM-Username': username,
|
|
175
|
+
'X-OpenAM-Password': password
|
|
220
176
|
}
|
|
221
|
-
|
|
222
|
-
|
|
177
|
+
};
|
|
178
|
+
const response1 = await step({}, config);
|
|
179
|
+
const skip2FA = checkAndHandle2FA(response1);
|
|
180
|
+
let response2 = {};
|
|
181
|
+
if (skip2FA.need2fa) {
|
|
182
|
+
response2 = await step(skip2FA.payload);
|
|
183
|
+
} else {
|
|
184
|
+
response2 = skip2FA.payload;
|
|
185
|
+
}
|
|
186
|
+
if ('tokenId' in response2) {
|
|
187
|
+
return response2['tokenId'];
|
|
223
188
|
}
|
|
189
|
+
return null;
|
|
224
190
|
}
|
|
191
|
+
|
|
225
192
|
/**
|
|
226
193
|
* Helper function to obtain an oauth2 authorization code
|
|
227
|
-
* @param {
|
|
228
|
-
* @param {
|
|
229
|
-
* @param {
|
|
230
|
-
* @returns {
|
|
194
|
+
* @param {string} redirectURL oauth2 redirect uri
|
|
195
|
+
* @param {string} codeChallenge PKCE code challenge
|
|
196
|
+
* @param {string} codeChallengeMethod PKCE code challenge method
|
|
197
|
+
* @returns {string} oauth2 authorization code or null
|
|
231
198
|
*/
|
|
232
|
-
|
|
233
|
-
|
|
234
199
|
async function getAuthCode(redirectURL, codeChallenge, codeChallengeMethod) {
|
|
235
200
|
try {
|
|
236
|
-
|
|
201
|
+
var _response$headers;
|
|
202
|
+
const bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScopes}&response_type=code&client_id=${adminClientId}&csrf=${state.getCookieValue()}&decision=allow&code_challenge=${codeChallenge}&code_challenge_method=${codeChallengeMethod}`;
|
|
237
203
|
const config = {
|
|
238
204
|
headers: {
|
|
239
205
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
240
|
-
}
|
|
206
|
+
},
|
|
207
|
+
maxRedirects: 0
|
|
241
208
|
};
|
|
242
|
-
|
|
243
|
-
|
|
209
|
+
let response = undefined;
|
|
210
|
+
try {
|
|
211
|
+
response = await authorize(bodyFormData, config);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
response = error.response;
|
|
214
|
+
}
|
|
244
215
|
if (response.status < 200 || response.status > 399) {
|
|
245
216
|
printMessage('error getting auth code', 'error');
|
|
246
217
|
printMessage('likely cause: mismatched parameters with OAuth client config', 'error');
|
|
247
218
|
return null;
|
|
248
219
|
}
|
|
249
|
-
|
|
250
|
-
const redirectLocationURL = response.request.res.responseUrl;
|
|
220
|
+
const redirectLocationURL = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.location;
|
|
251
221
|
const queryObject = url.parse(redirectLocationURL, true).query;
|
|
252
|
-
|
|
253
222
|
if ('code' in queryObject) {
|
|
254
223
|
return queryObject.code;
|
|
255
224
|
}
|
|
256
|
-
|
|
257
225
|
printMessage('auth code not found', 'error');
|
|
258
226
|
return null;
|
|
259
227
|
} catch (error) {
|
|
228
|
+
var _error$response;
|
|
260
229
|
printMessage(`error getting auth code - ${error.message}`, 'error');
|
|
261
|
-
printMessage(error.response.data, 'error');
|
|
230
|
+
printMessage((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, 'error');
|
|
231
|
+
debugMessage(error.stack);
|
|
262
232
|
return null;
|
|
263
233
|
}
|
|
264
234
|
}
|
|
235
|
+
|
|
265
236
|
/**
|
|
266
237
|
* Helper function to obtain oauth2 access token
|
|
267
|
-
* @returns {
|
|
238
|
+
* @returns {Promise<string | null>} access token or null
|
|
268
239
|
*/
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
async function getAccessToken() {
|
|
240
|
+
async function getAccessTokenForUser() {
|
|
272
241
|
try {
|
|
273
242
|
const verifier = encodeBase64Url(randomBytes(32));
|
|
274
243
|
const challenge = encodeBase64Url(createHash('sha256').update(verifier).digest());
|
|
275
244
|
const challengeMethod = 'S256';
|
|
276
|
-
const redirectURL = url.resolve(
|
|
245
|
+
const redirectURL = url.resolve(state.getHost(), redirectUrlTemplate);
|
|
277
246
|
const authCode = await getAuthCode(redirectURL, challenge, challengeMethod);
|
|
278
|
-
|
|
279
247
|
if (authCode == null) {
|
|
280
248
|
printMessage('error getting auth code', 'error');
|
|
281
249
|
return null;
|
|
282
250
|
}
|
|
283
|
-
|
|
284
251
|
let response = null;
|
|
285
|
-
|
|
286
|
-
if (storage.session.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY) {
|
|
252
|
+
if (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY) {
|
|
287
253
|
const config = {
|
|
288
254
|
auth: {
|
|
289
255
|
username: adminClientId,
|
|
@@ -296,65 +262,166 @@ async function getAccessToken() {
|
|
|
296
262
|
const bodyFormData = `client_id=${adminClientId}&redirect_uri=${redirectURL}&grant_type=authorization_code&code=${authCode}&code_verifier=${verifier}`;
|
|
297
263
|
response = await accessToken(bodyFormData);
|
|
298
264
|
}
|
|
299
|
-
|
|
300
|
-
if (response.status < 200 || response.status > 399) {
|
|
301
|
-
printMessage(`access token call returned ${response.status}`, 'error');
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
265
|
if ('access_token' in response.data) {
|
|
306
|
-
|
|
307
|
-
return '';
|
|
266
|
+
return response.data.access_token;
|
|
308
267
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return null;
|
|
268
|
+
printMessage('No access token in response.', 'error');
|
|
269
|
+
} catch (error) {
|
|
270
|
+
var _error$response2;
|
|
271
|
+
debugMessage(`Error getting access token for user: ${error}`);
|
|
272
|
+
debugMessage((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data);
|
|
315
273
|
}
|
|
274
|
+
return null;
|
|
316
275
|
}
|
|
276
|
+
function createPayload(serviceAccountId) {
|
|
277
|
+
const u = parseUrl(state.getHost());
|
|
278
|
+
const aud = `${u.origin}:${u.port ? u.port : u.protocol === 'https' ? '443' : '80'}${u.pathname}/oauth2/access_token`;
|
|
279
|
+
|
|
280
|
+
// Cross platform way of setting JWT expiry time 3 minutes in the future, expressed as number of seconds since EPOCH
|
|
281
|
+
const exp = Math.floor(new Date().getTime() / 1000 + 180);
|
|
282
|
+
|
|
283
|
+
// A unique ID for the JWT which is required when requesting the openid scope
|
|
284
|
+
const jti = v4();
|
|
285
|
+
const iss = serviceAccountId;
|
|
286
|
+
const sub = serviceAccountId;
|
|
287
|
+
|
|
288
|
+
// Create the payload for our bearer token
|
|
289
|
+
const payload = {
|
|
290
|
+
iss,
|
|
291
|
+
sub,
|
|
292
|
+
aud,
|
|
293
|
+
exp,
|
|
294
|
+
jti
|
|
295
|
+
};
|
|
296
|
+
return payload;
|
|
297
|
+
}
|
|
298
|
+
|
|
317
299
|
/**
|
|
318
|
-
* Get
|
|
319
|
-
* @param {
|
|
320
|
-
* @
|
|
300
|
+
* Get access token for service account
|
|
301
|
+
* @param {string} serviceAccountId UUID of service account
|
|
302
|
+
* @param {JwkRsa} jwk Java Wek Key
|
|
303
|
+
* @returns {string | null} Access token or null
|
|
321
304
|
*/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
} else {
|
|
338
|
-
return false;
|
|
339
|
-
}
|
|
305
|
+
export async function getAccessTokenForServiceAccount(serviceAccountId, jwk) {
|
|
306
|
+
debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: start`);
|
|
307
|
+
const payload = createPayload(serviceAccountId);
|
|
308
|
+
debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: payload:`);
|
|
309
|
+
debugMessage(payload);
|
|
310
|
+
const jwt = await createSignedJwtToken(payload, jwk);
|
|
311
|
+
debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: jwt:`);
|
|
312
|
+
debugMessage(jwt);
|
|
313
|
+
const bodyFormData = `assertion=${jwt}&client_id=service-account&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&scope=${serviceAccountScopes}`;
|
|
314
|
+
const response = await accessToken(bodyFormData);
|
|
315
|
+
if ('access_token' in response.data) {
|
|
316
|
+
debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: token:`);
|
|
317
|
+
debugMessage(response.data.access_token);
|
|
318
|
+
debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: end`);
|
|
319
|
+
return response.data.access_token;
|
|
340
320
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
321
|
+
debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: No access token in response.`);
|
|
322
|
+
debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: end`);
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
async function determineDeploymentTypeAndDefaultRealmAndVersion() {
|
|
326
|
+
debugMessage(`AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: start`);
|
|
327
|
+
if (!state.getDeploymentType()) {
|
|
328
|
+
state.setDeploymentType(await determineDeploymentType());
|
|
346
329
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
330
|
+
determineDefaultRealm(state.getDeploymentType());
|
|
331
|
+
debugMessage(`AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: realm=${state.getRealm()}, type=${state.getDeploymentType()}`);
|
|
332
|
+
const versionInfo = (await getServerVersionInfo()).data;
|
|
333
|
+
|
|
334
|
+
// https://github.com/rockcarver/frodo-cli/issues/109
|
|
335
|
+
debugMessage(`Full version: ${versionInfo.fullVersion}`);
|
|
336
|
+
const version = await getSemanticVersion(versionInfo);
|
|
337
|
+
state.setAmVersion(version);
|
|
338
|
+
debugMessage(`AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: end`);
|
|
339
|
+
}
|
|
340
|
+
async function getLoggedInSubject() {
|
|
341
|
+
let subjectString = `user ${state.getUsername()}`;
|
|
342
|
+
if (state.getUseBearerTokenForAmApis()) {
|
|
343
|
+
const name = (await getManagedObject('svcacct', state.getServiceAccountId(), ['name'])).data.name;
|
|
344
|
+
subjectString = `service account ${name} [${state.getServiceAccountId()}]`;
|
|
352
345
|
}
|
|
346
|
+
return subjectString;
|
|
347
|
+
}
|
|
353
348
|
|
|
354
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Get tokens
|
|
351
|
+
* @param {boolean} save true to save a connection profile upon successful authentication, false otherwise
|
|
352
|
+
* @returns {Promise<boolean>} true if tokens were successfully obtained, false otherwise
|
|
353
|
+
*/
|
|
354
|
+
export async function getTokens() {
|
|
355
|
+
if (!state.getHost()) {
|
|
356
|
+
printMessage(`No host specified and FRODO_HOST env variable not set!`, 'error');
|
|
355
357
|
return false;
|
|
356
358
|
}
|
|
359
|
+
try {
|
|
360
|
+
// if username/password on cli are empty, try to read from connections.json
|
|
361
|
+
if (state.getUsername() == null && state.getPassword() == null && !state.getServiceAccountId() && !state.getServiceAccountJwk()) {
|
|
362
|
+
const conn = await getConnectionProfile();
|
|
363
|
+
if (conn) {
|
|
364
|
+
state.setHost(conn.tenant);
|
|
365
|
+
state.setUsername(conn.username);
|
|
366
|
+
state.setPassword(conn.password);
|
|
367
|
+
state.setAuthenticationService(conn.authenticationService);
|
|
368
|
+
state.setAuthenticationHeaderOverrides(conn.authenticationHeaderOverrides);
|
|
369
|
+
state.setServiceAccountId(conn.svcacctId);
|
|
370
|
+
state.setServiceAccountJwk(conn.svcacctJwk);
|
|
371
|
+
} else {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
// now that we have the full tenant URL we can lookup the cookie name
|
|
376
|
+
state.setCookieName(await determineCookieName());
|
|
357
377
|
|
|
358
|
-
|
|
378
|
+
// use service account to login?
|
|
379
|
+
if (state.getServiceAccountId() && state.getServiceAccountJwk()) {
|
|
380
|
+
debugMessage(`AuthenticateOps.getTokens: Authenticating with service account ${state.getServiceAccountId()}`);
|
|
381
|
+
try {
|
|
382
|
+
const token = await getAccessTokenForServiceAccount(state.getServiceAccountId(), state.getServiceAccountJwk());
|
|
383
|
+
state.setBearerToken(token);
|
|
384
|
+
state.setUseBearerTokenForAmApis(true);
|
|
385
|
+
await determineDeploymentTypeAndDefaultRealmAndVersion();
|
|
386
|
+
} catch (saErr) {
|
|
387
|
+
var _saErr$response, _saErr$response$data, _saErr$response2, _saErr$response2$data;
|
|
388
|
+
throw new Error(`Service account login error: ${((_saErr$response = saErr.response) === null || _saErr$response === void 0 ? void 0 : (_saErr$response$data = _saErr$response.data) === null || _saErr$response$data === void 0 ? void 0 : _saErr$response$data.error_description) || ((_saErr$response2 = saErr.response) === null || _saErr$response2 === void 0 ? void 0 : (_saErr$response2$data = _saErr$response2.data) === null || _saErr$response2$data === void 0 ? void 0 : _saErr$response2$data.message)}`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
// use user account to login
|
|
392
|
+
else if (state.getUsername() && state.getPassword()) {
|
|
393
|
+
debugMessage(`AuthenticateOps.getTokens: Authenticating with user account ${state.getUsername()}`);
|
|
394
|
+
const token = await authenticate(state.getUsername(), state.getPassword());
|
|
395
|
+
if (token) state.setCookieValue(token);
|
|
396
|
+
await determineDeploymentTypeAndDefaultRealmAndVersion();
|
|
397
|
+
if (state.getCookieValue() && !state.getBearerToken() && (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY || state.getDeploymentType() === globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY)) {
|
|
398
|
+
const accessToken = await getAccessTokenForUser();
|
|
399
|
+
if (accessToken) state.setBearerToken(accessToken);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// incomplete or no credentials
|
|
403
|
+
else {
|
|
404
|
+
printMessage(`Incomplete or no credentials!`, 'error');
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
if (state.getCookieValue() || state.getUseBearerTokenForAmApis() && state.getBearerToken()) {
|
|
408
|
+
// https://github.com/rockcarver/frodo-cli/issues/102
|
|
409
|
+
printMessage(`Connected to ${state.getHost()} [${state.getRealm() ? state.getRealm() : 'root'}] as ${await getLoggedInSubject()}`, 'info');
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
} catch (error) {
|
|
413
|
+
var _error$response3, _error$response3$data, _error$response4, _error$response4$data, _error$response5;
|
|
414
|
+
// regular error
|
|
415
|
+
printMessage(error.message, 'error');
|
|
416
|
+
// axios error am api
|
|
417
|
+
printMessage((_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : (_error$response3$data = _error$response3.data) === null || _error$response3$data === void 0 ? void 0 : _error$response3$data.message, 'error');
|
|
418
|
+
// axios error am oauth2 api
|
|
419
|
+
printMessage((_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : (_error$response4$data = _error$response4.data) === null || _error$response4$data === void 0 ? void 0 : _error$response4$data.error_description, 'error');
|
|
420
|
+
// axios error data
|
|
421
|
+
debugMessage((_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : _error$response5.data);
|
|
422
|
+
// stack trace
|
|
423
|
+
debugMessage(error.stack || new Error().stack);
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
359
426
|
}
|
|
360
427
|
//# sourceMappingURL=AuthenticateOps.js.map
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { Authenticate, state } from '../index';
|
|
2
2
|
describe('AuthenticationOps', () => {
|
|
3
3
|
test('getTokens() 1: ', async () => {
|
|
4
|
-
state.
|
|
5
|
-
state.
|
|
6
|
-
|
|
4
|
+
state.setHost(process.env.FRODO_HOST || 'frodo-dev');
|
|
5
|
+
state.setRealm('alpha');
|
|
7
6
|
if (process.env.FRODO_HOST && process.env.FRODO_USER && process.env.FRODO_PASSWORD) {
|
|
8
|
-
state.
|
|
9
|
-
state.
|
|
7
|
+
state.setUsername(process.env.FRODO_USER);
|
|
8
|
+
state.setPassword(process.env.FRODO_PASSWORD);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
await Authenticate.getTokens();
|
|
13
|
-
expect(state.
|
|
14
|
-
expect(state.
|
|
15
|
-
expect(state.
|
|
11
|
+
expect(state.getCookieName()).toBeTruthy();
|
|
12
|
+
expect(state.getCookieValue()).toBeTruthy();
|
|
13
|
+
expect(state.getBearerToken()).toBeTruthy();
|
|
16
14
|
});
|
|
17
15
|
});
|
|
18
16
|
//# sourceMappingURL=AuthenticateOps.test.js.map
|