@rockcarver/frodo-lib 2.0.0-71 → 2.0.0-72

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 (227) hide show
  1. package/build.zip +0 -0
  2. package/cjs/FrodoError.js +34 -0
  3. package/cjs/FrodoError.js.map +1 -0
  4. package/cjs/ops/AuthenticateOps.js +62 -148
  5. package/cjs/ops/AuthenticateOps.js.map +1 -1
  6. package/cjs/ops/CallbackOps.js +6 -0
  7. package/cjs/ops/CallbackOps.js.map +1 -0
  8. package/docs/assets/navigation.js +1 -1
  9. package/docs/assets/search.js +1 -1
  10. package/docs/index.html +2 -2
  11. package/docs/interfaces/Reference.AdminFederationExportInterface.html +2 -2
  12. package/docs/interfaces/Reference.AgentExportInterface.html +2 -2
  13. package/docs/interfaces/Reference.ApplicationExportInterface.html +9 -9
  14. package/docs/interfaces/Reference.AuthenticationSettingsExportInterface.html +2 -2
  15. package/docs/interfaces/Reference.CirclesOfTrustExportInterface.html +2 -2
  16. package/docs/interfaces/Reference.ConfigEntityExportInterface.html +2 -2
  17. package/docs/interfaces/Reference.ConfigEntityImportOptions.html +3 -3
  18. package/docs/interfaces/Reference.ConnectionProfileInterface.html +2 -2
  19. package/docs/interfaces/Reference.ConnectionsFileInterface.html +1 -1
  20. package/docs/interfaces/Reference.ConnectorExportInterface.html +2 -2
  21. package/docs/interfaces/Reference.ConnectorExportOptions.html +4 -4
  22. package/docs/interfaces/Reference.ConnectorImportOptions.html +3 -3
  23. package/docs/interfaces/Reference.ConnectorServerStatusInterface.html +2 -2
  24. package/docs/interfaces/Reference.EmailTemplateExportInterface.html +2 -2
  25. package/docs/interfaces/Reference.EnvInfoInterface.html +2 -2
  26. package/docs/interfaces/Reference.ExportMetaData.html +2 -2
  27. package/docs/interfaces/Reference.FeatureInterface.html +2 -2
  28. package/docs/interfaces/Reference.FullExportInterface.html +2 -2
  29. package/docs/interfaces/Reference.FullExportOptions.html +6 -6
  30. package/docs/interfaces/Reference.FullImportOptions.html +8 -8
  31. package/docs/interfaces/Reference.FullService.html +2 -2
  32. package/docs/interfaces/Reference.IdObjectSkeletonInterface.html +2 -2
  33. package/docs/interfaces/Reference.InnerNodeRefSkeletonInterface.html +2 -2
  34. package/docs/interfaces/Reference.JwkInterface.html +2 -2
  35. package/docs/interfaces/Reference.JwksInterface.html +2 -2
  36. package/docs/interfaces/Reference.ManagedObjectPatchOperationInterface.html +3 -3
  37. package/docs/interfaces/Reference.MappingExportInterface.html +2 -2
  38. package/docs/interfaces/Reference.MappingImportOptions.html +3 -3
  39. package/docs/interfaces/Reference.MultiTreeExportInterface.html +2 -2
  40. package/docs/interfaces/Reference.NoIdObjectSkeletonInterface.html +2 -2
  41. package/docs/interfaces/Reference.NodeRefSkeletonInterface.html +2 -2
  42. package/docs/interfaces/Reference.OAuth2ClientExportInterface.html +2 -2
  43. package/docs/interfaces/Reference.OAuth2ClientExportOptions.html +4 -4
  44. package/docs/interfaces/Reference.OAuth2ClientImportOptions.html +3 -3
  45. package/docs/interfaces/Reference.OAuth2TrustedJwtIssuerExportInterface.html +2 -2
  46. package/docs/interfaces/Reference.OAuth2TrustedJwtIssuerExportOptions.html +4 -4
  47. package/docs/interfaces/Reference.OAuth2TrustedJwtIssuerImportOptions.html +3 -3
  48. package/docs/interfaces/Reference.PlatformInfoInterface.html +2 -2
  49. package/docs/interfaces/Reference.PolicyExportInterface.html +2 -2
  50. package/docs/interfaces/Reference.PolicyExportOptions.html +5 -5
  51. package/docs/interfaces/Reference.PolicyImportOptions.html +5 -5
  52. package/docs/interfaces/Reference.PolicySetExportInterface.html +2 -2
  53. package/docs/interfaces/Reference.PolicySetExportOptions.html +5 -5
  54. package/docs/interfaces/Reference.PolicySetImportOptions.html +4 -4
  55. package/docs/interfaces/Reference.ResourceTypeExportInterface.html +2 -2
  56. package/docs/interfaces/Reference.Saml2EntitiesExportOptions.html +2 -2
  57. package/docs/interfaces/Reference.Saml2EntitiesImportOptions.html +2 -2
  58. package/docs/interfaces/Reference.Saml2ExportInterface.html +2 -2
  59. package/docs/interfaces/Reference.ScriptExportInterface.html +2 -2
  60. package/docs/interfaces/Reference.ScriptImportOptions.html +4 -4
  61. package/docs/interfaces/Reference.SecretsExportInterface.html +2 -2
  62. package/docs/interfaces/Reference.SecureConnectionProfileInterface.html +2 -2
  63. package/docs/interfaces/Reference.ServiceExportInterface.html +2 -2
  64. package/docs/interfaces/Reference.ServiceImportOptions.html +5 -5
  65. package/docs/interfaces/Reference.ServiceListItem.html +4 -4
  66. package/docs/interfaces/Reference.ServiceNextDescendent.html +1 -1
  67. package/docs/interfaces/Reference.SingleTreeExportInterface.html +2 -2
  68. package/docs/interfaces/Reference.SocialIdentityProviderImportOptions.html +3 -3
  69. package/docs/interfaces/Reference.SocialProviderExportInterface.html +2 -2
  70. package/docs/interfaces/Reference.StateInterface.html +2 -2
  71. package/docs/interfaces/Reference.SystemObjectPatchOperationInterface.html +2 -2
  72. package/docs/interfaces/Reference.SystemStatusInterface.html +2 -2
  73. package/docs/interfaces/Reference.ThemeExportInterface.html +2 -2
  74. package/docs/interfaces/Reference.TokenCacheInterface.html +1 -1
  75. package/docs/interfaces/Reference.TreeDependencyMapInterface.html +1 -1
  76. package/docs/interfaces/Reference.TreeExportOptions.html +5 -5
  77. package/docs/interfaces/Reference.TreeExportResolverInterface.html +1 -1
  78. package/docs/interfaces/Reference.TreeImportOptions.html +4 -4
  79. package/docs/interfaces/Reference.UiConfigInterface.html +2 -2
  80. package/docs/interfaces/Reference.Updates.html +4 -4
  81. package/docs/interfaces/Reference.VariablesExportInterface.html +2 -2
  82. package/docs/modules/Reference.html +7 -2
  83. package/docs/modules.html +2 -2
  84. package/docs/types/Reference.AccessTokenMetaType.html +1 -1
  85. package/docs/types/Reference.AccessTokenResponseType.html +1 -1
  86. package/docs/types/Reference.Admin.html +1 -1
  87. package/docs/types/Reference.AdminFederation.html +15 -15
  88. package/docs/types/Reference.AdminFederationConfigSkeleton.html +1 -1
  89. package/docs/types/Reference.Agent.html +53 -53
  90. package/docs/types/Reference.AgentSkeleton.html +1 -1
  91. package/docs/types/Reference.AgentType.html +1 -1
  92. package/docs/types/Reference.AmServiceSkeleton.html +1 -1
  93. package/docs/types/Reference.AmServiceType.html +1 -1
  94. package/docs/types/Reference.Application.html +19 -19
  95. package/docs/types/Reference.ApplicationExportOptions.html +2 -2
  96. package/docs/types/Reference.ApplicationImportOptions.html +2 -2
  97. package/docs/types/Reference.ApplicationSkeleton.html +1 -1
  98. package/docs/types/Reference.Authenticate.html +5 -4
  99. package/docs/types/Reference.AuthenticationSettings.html +5 -5
  100. package/docs/types/Reference.AuthenticationSettingsSkeleton.html +1 -1
  101. package/docs/types/Reference.Base64.html +1 -1
  102. package/docs/types/Reference.Callback.html +1 -0
  103. package/docs/types/Reference.CallbackHandler.html +1 -0
  104. package/docs/types/Reference.CallbackKeyValuePair.html +1 -0
  105. package/docs/types/Reference.CallbackType.html +1 -0
  106. package/docs/types/Reference.CircleOfTrustSkeleton.html +1 -1
  107. package/docs/types/Reference.CirclesOfTrust.html +15 -15
  108. package/docs/types/Reference.Config.html +3 -3
  109. package/docs/types/Reference.ConnectionProfile.html +9 -9
  110. package/docs/types/Reference.Connector.html +13 -13
  111. package/docs/types/Reference.ConnectorSkeleton.html +1 -1
  112. package/docs/types/Reference.Constants.html +1 -1
  113. package/docs/types/Reference.DeleteJourneyStatus.html +1 -1
  114. package/docs/types/Reference.DeleteJourneysStatus.html +1 -1
  115. package/docs/types/Reference.EmailTemplate.html +13 -13
  116. package/docs/types/Reference.EmailTemplateSkeleton.html +1 -1
  117. package/docs/types/Reference.ExportImport.html +7 -7
  118. package/docs/types/Reference.FRUtils.html +1 -1
  119. package/docs/types/Reference.Feature.html +3 -3
  120. package/docs/types/Reference.Frodo.html +4 -4
  121. package/docs/types/Reference.GatewayAgentType.html +1 -1
  122. package/docs/types/Reference.IdmConfig.html +18 -18
  123. package/docs/types/Reference.IdmConfigStub.html +1 -1
  124. package/docs/types/Reference.IdmSystem.html +14 -14
  125. package/docs/types/Reference.Idp.html +21 -21
  126. package/docs/types/Reference.Info.html +2 -2
  127. package/docs/types/Reference.JavaAgentType.html +1 -1
  128. package/docs/types/Reference.Jose.html +1 -1
  129. package/docs/types/Reference.Journey.html +28 -28
  130. package/docs/types/Reference.JourneyClassificationType.html +1 -1
  131. package/docs/types/Reference.Json.html +7 -7
  132. package/docs/types/Reference.JwkRsa.html +1 -1
  133. package/docs/types/Reference.JwkRsaPublic.html +1 -1
  134. package/docs/types/Reference.Log.html +13 -13
  135. package/docs/types/Reference.LogApiKey.html +1 -1
  136. package/docs/types/Reference.LogEventPayloadSkeleton.html +1 -1
  137. package/docs/types/Reference.LogEventSkeleton.html +1 -1
  138. package/docs/types/Reference.ManagedObject.html +11 -11
  139. package/docs/types/Reference.Mapping.html +15 -15
  140. package/docs/types/Reference.MappingPolicy.html +1 -1
  141. package/docs/types/Reference.MappingProperty.html +1 -1
  142. package/docs/types/Reference.MappingSkeleton.html +1 -1
  143. package/docs/types/Reference.Node.html +16 -16
  144. package/docs/types/Reference.NodeClassificationType.html +1 -1
  145. package/docs/types/Reference.NodeSkeleton.html +1 -1
  146. package/docs/types/Reference.OAuth2Client.html +16 -16
  147. package/docs/types/Reference.OAuth2ClientSkeleton.html +1 -1
  148. package/docs/types/Reference.OAuth2Oidc.html +1 -1
  149. package/docs/types/Reference.OAuth2Provider.html +6 -6
  150. package/docs/types/Reference.OAuth2ProviderSkeleton.html +1 -1
  151. package/docs/types/Reference.OAuth2TrustedJwtIssuer.html +16 -16
  152. package/docs/types/Reference.OAuth2TrustedJwtIssuerSkeleton.html +1 -1
  153. package/docs/types/Reference.ObjectPropertyFlag.html +1 -1
  154. package/docs/types/Reference.ObjectPropertyNativeType.html +1 -1
  155. package/docs/types/Reference.ObjectPropertySkeleton.html +1 -1
  156. package/docs/types/Reference.ObjectPropertyType.html +1 -1
  157. package/docs/types/Reference.ObjectTypeSkeleton.html +1 -1
  158. package/docs/types/Reference.Organization.html +4 -4
  159. package/docs/types/Reference.PagedResult.html +1 -1
  160. package/docs/types/Reference.PlatformInfo.html +1 -1
  161. package/docs/types/Reference.Policy.html +18 -18
  162. package/docs/types/Reference.PolicyCondition.html +1 -1
  163. package/docs/types/Reference.PolicyConditionType.html +1 -1
  164. package/docs/types/Reference.PolicySet.html +11 -11
  165. package/docs/types/Reference.PolicySetSkeleton.html +1 -1
  166. package/docs/types/Reference.PolicySkeleton.html +1 -1
  167. package/docs/types/Reference.ProgressIndicatorStatusType.html +1 -1
  168. package/docs/types/Reference.ProgressIndicatorType.html +1 -1
  169. package/docs/types/Reference.Readable.html +1 -1
  170. package/docs/types/Reference.Realm.html +13 -13
  171. package/docs/types/Reference.RealmSkeleton.html +1 -1
  172. package/docs/types/Reference.Recon.html +6 -6
  173. package/docs/types/Reference.ReconStatusType.html +1 -1
  174. package/docs/types/Reference.ReconType.html +1 -1
  175. package/docs/types/Reference.ResourceType.html +18 -18
  176. package/docs/types/Reference.ResourceTypeSkeleton.html +1 -1
  177. package/docs/types/Reference.Saml2.html +19 -19
  178. package/docs/types/Reference.Saml2ProiderLocation.html +1 -1
  179. package/docs/types/Reference.Saml2ProviderSkeleton.html +1 -1
  180. package/docs/types/Reference.Saml2ProviderStub.html +1 -1
  181. package/docs/types/Reference.Script.html +18 -18
  182. package/docs/types/Reference.ScriptContext.html +1 -1
  183. package/docs/types/Reference.ScriptLanguage.html +1 -1
  184. package/docs/types/Reference.ScriptSkeleton.html +1 -1
  185. package/docs/types/Reference.ScriptValidation.html +1 -1
  186. package/docs/types/Reference.Secret.html +22 -22
  187. package/docs/types/Reference.SecretEncodingType.html +2 -2
  188. package/docs/types/Reference.SecretSkeleton.html +2 -2
  189. package/docs/types/Reference.Service.html +9 -9
  190. package/docs/types/Reference.ServiceAccount.html +4 -4
  191. package/docs/types/Reference.ServiceAccountType.html +1 -1
  192. package/docs/types/Reference.Session.html +2 -2
  193. package/docs/types/Reference.SessionInfoType.html +1 -1
  194. package/docs/types/Reference.SocialIdpSkeleton.html +1 -1
  195. package/docs/types/Reference.Startup.html +3 -3
  196. package/docs/types/Reference.State.html +7 -7
  197. package/docs/types/Reference.Theme.html +20 -20
  198. package/docs/types/Reference.ThemeSkeleton.html +1 -1
  199. package/docs/types/Reference.TokenCache.html +16 -16
  200. package/docs/types/Reference.TokenInfoResponseType.html +1 -1
  201. package/docs/types/Reference.Tokens.html +1 -0
  202. package/docs/types/Reference.TreeSkeleton.html +1 -1
  203. package/docs/types/Reference.UserSessionMetaType.html +1 -1
  204. package/docs/types/Reference.Variable.html +13 -13
  205. package/docs/types/Reference.VariableExpressionType.html +2 -2
  206. package/docs/types/Reference.VariableSkeleton.html +2 -2
  207. package/docs/types/Reference.Version.html +1 -1
  208. package/docs/types/Reference.VersionOfSecretSkeleton.html +2 -2
  209. package/docs/types/Reference.VersionOfSecretStatus.html +1 -1
  210. package/docs/types/Reference.WebAgentType.html +1 -1
  211. package/docs/types/Reference.Writable.html +1 -1
  212. package/docs/types/Reference.tokenType.html +1 -1
  213. package/docs/variables/frodo.html +2 -2
  214. package/docs/variables/state.html +2 -2
  215. package/esm/FrodoError.js +23 -0
  216. package/esm/FrodoError.js.map +1 -0
  217. package/esm/ops/AuthenticateOps.js +44 -132
  218. package/esm/ops/AuthenticateOps.js.map +1 -1
  219. package/esm/ops/CallbackOps.js +2 -0
  220. package/esm/ops/CallbackOps.js.map +1 -0
  221. package/package.json +1 -2
  222. package/types/FrodoError.d.ts +7 -0
  223. package/types/FrodoError.d.ts.map +1 -0
  224. package/types/ops/AuthenticateOps.d.ts +16 -6
  225. package/types/ops/AuthenticateOps.d.ts.map +1 -1
  226. package/types/ops/CallbackOps.d.ts +12 -0
  227. package/types/ops/CallbackOps.d.ts.map +1 -0
package/build.zip CHANGED
Binary file
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FrodoError = void 0;
7
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
9
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
+ class FrodoError extends Error {
11
+ constructor(message) {
12
+ var originalErrors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
13
+ super(message);
14
+ _defineProperty(this, "originalErrors", []);
15
+ this.name = 'FrodoError';
16
+ if (originalErrors && Array.isArray(originalErrors)) {
17
+ this.originalErrors = originalErrors;
18
+ } else if (originalErrors) {
19
+ this.originalErrors = [originalErrors];
20
+ }
21
+ }
22
+ getOriginalErrors() {
23
+ return this.originalErrors;
24
+ }
25
+ getCombinedMessage() {
26
+ var combinedMessage = this.message;
27
+ this.originalErrors.forEach(error => {
28
+ combinedMessage += '\n ' + error.message;
29
+ });
30
+ return combinedMessage;
31
+ }
32
+ }
33
+ exports.FrodoError = FrodoError;
34
+ //# sourceMappingURL=FrodoError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FrodoError.js","names":["FrodoError","Error","constructor","message","originalErrors","arguments","length","undefined","_defineProperty","name","Array","isArray","getOriginalErrors","getCombinedMessage","combinedMessage","forEach","error","exports"],"sources":["../src/FrodoError.ts"],"sourcesContent":["export class FrodoError extends Error {\n originalErrors: Error[] = [];\n constructor(message: string, originalErrors: Error | Error[] = null) {\n super(message);\n this.name = 'FrodoError';\n if (originalErrors && Array.isArray(originalErrors)) {\n this.originalErrors = originalErrors;\n } else if (originalErrors) {\n this.originalErrors = [originalErrors as Error];\n }\n }\n\n getOriginalErrors(): Error[] {\n return this.originalErrors;\n }\n\n getCombinedMessage(): string {\n let combinedMessage = this.message;\n this.originalErrors.forEach((error) => {\n combinedMessage += '\\n ' + error.message;\n });\n return combinedMessage;\n }\n}\n"],"mappings":";;;;;;;;;AAAO,MAAMA,UAAU,SAASC,KAAK,CAAC;EAEpCC,WAAWA,CAACC,OAAe,EAA0C;IAAA,IAAxCC,cAA+B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;IACjE,KAAK,CAACF,OAAO,CAAC;IAACK,eAAA,yBAFS,EAAE;IAG1B,IAAI,CAACC,IAAI,GAAG,YAAY;IACxB,IAAIL,cAAc,IAAIM,KAAK,CAACC,OAAO,CAACP,cAAc,CAAC,EAAE;MACnD,IAAI,CAACA,cAAc,GAAGA,cAAc;IACtC,CAAC,MAAM,IAAIA,cAAc,EAAE;MACzB,IAAI,CAACA,cAAc,GAAG,CAACA,cAAc,CAAU;IACjD;EACF;EAEAQ,iBAAiBA,CAAA,EAAY;IAC3B,OAAO,IAAI,CAACR,cAAc;EAC5B;EAEAS,kBAAkBA,CAAA,EAAW;IAC3B,IAAIC,eAAe,GAAG,IAAI,CAACX,OAAO;IAClC,IAAI,CAACC,cAAc,CAACW,OAAO,CAAEC,KAAK,IAAK;MACrCF,eAAe,IAAI,MAAM,GAAGE,KAAK,CAACb,OAAO;IAC3C,CAAC,CAAC;IACF,OAAOW,eAAe;EACxB;AACF;AAACG,OAAA,CAAAjB,UAAA,GAAAA,UAAA"}
@@ -8,11 +8,11 @@ exports.getFreshSaBearerToken = getFreshSaBearerToken;
8
8
  exports.getSaBearerToken = getSaBearerToken;
9
9
  exports.getTokens = getTokens;
10
10
  var _crypto = require("crypto");
11
- var _readlineSync = _interopRequireDefault(require("readline-sync"));
12
11
  var _url = _interopRequireDefault(require("url"));
13
12
  var _uuid = require("uuid");
14
13
  var _AuthenticateApi = require("../api/AuthenticateApi.js");
15
14
  var _ServerInfoApi = require("../api/ServerInfoApi.js");
15
+ var _FrodoError = require("../FrodoError.js");
16
16
  var _Constants = _interopRequireDefault(require("../shared/Constants.js"));
17
17
  var _Base64Utils = require("../utils/Base64Utils.js");
18
18
  var _Console = require("../utils/Console.js");
@@ -33,9 +33,11 @@ var _default = state => {
33
33
  return _asyncToGenerator(function* () {
34
34
  var forceLoginAsUser = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : false;
35
35
  var autoRefresh = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : true;
36
+ var callbackHandler = _arguments.length > 2 && _arguments[2] !== undefined ? _arguments[2] : null;
36
37
  return getTokens({
37
38
  forceLoginAsUser,
38
39
  autoRefresh,
40
+ callbackHandler,
39
41
  state
40
42
  });
41
43
  })();
@@ -95,7 +97,12 @@ function _determineCookieName() {
95
97
  });
96
98
  return _determineCookieName.apply(this, arguments);
97
99
  }
98
- function checkAndHandle2FA(payload, state) {
100
+ function checkAndHandle2FA(_ref) {
101
+ var {
102
+ payload,
103
+ otpCallbackHandler,
104
+ state
105
+ } = _ref;
99
106
  (0, _Console.debugMessage)({
100
107
  message: "AuthenticateOps.checkAndHandle2FA: start",
101
108
  state
@@ -169,12 +176,8 @@ function checkAndHandle2FA(payload, state) {
169
176
  message: "AuthenticateOps.checkAndHandle2FA: need2fa=true, skippable=false",
170
177
  state
171
178
  });
172
- (0, _Console.printMessage)({
173
- message: '2FA is enabled and required for this user...',
174
- state
175
- });
176
- var code = _readlineSync.default.question("".concat(callback.output[0].value, ": "));
177
- callback.input[0].value = code;
179
+ if (!otpCallbackHandler) throw new _FrodoError.FrodoError("2fa required but no otpCallback function provided.");
180
+ callback = otpCallbackHandler(callback);
178
181
  (0, _Console.debugMessage)({
179
182
  message: "AuthenticateOps.checkAndHandle2FA: end [need2fa=true, skippable=false, factor=Code]",
180
183
  state
@@ -348,10 +351,11 @@ function getFreshUserSessionToken(_x3) {
348
351
  * @returns {Promise<UserSessionMetaType>} session token or null
349
352
  */
350
353
  function _getFreshUserSessionToken() {
351
- _getFreshUserSessionToken = _asyncToGenerator(function* (_ref) {
354
+ _getFreshUserSessionToken = _asyncToGenerator(function* (_ref2) {
352
355
  var {
356
+ otpCallbackHandler,
353
357
  state
354
- } = _ref;
358
+ } = _ref2;
355
359
  (0, _Console.debugMessage)({
356
360
  message: "AuthenticateOps.getFreshUserSessionToken: start",
357
361
  state
@@ -371,7 +375,11 @@ function _getFreshUserSessionToken() {
371
375
  var steps = 0;
372
376
  var maxSteps = 3;
373
377
  do {
374
- skip2FA = checkAndHandle2FA(response, state);
378
+ skip2FA = checkAndHandle2FA({
379
+ payload: response,
380
+ otpCallbackHandler: otpCallbackHandler,
381
+ state
382
+ });
375
383
 
376
384
  // throw exception if 2fa required but factor not supported by frodo (e.g. WebAuthN)
377
385
  if (!skip2FA.supported) {
@@ -411,7 +419,7 @@ function _getFreshUserSessionToken() {
411
419
  });
412
420
  return _getFreshUserSessionToken.apply(this, arguments);
413
421
  }
414
- function getUserSessionToken(_x4) {
422
+ function getUserSessionToken(_x4, _x5) {
415
423
  return _getUserSessionToken.apply(this, arguments);
416
424
  }
417
425
  /**
@@ -423,7 +431,7 @@ function getUserSessionToken(_x4) {
423
431
  * @returns {string} oauth2 authorization code or null
424
432
  */
425
433
  function _getUserSessionToken() {
426
- _getUserSessionToken = _asyncToGenerator(function* (state) {
434
+ _getUserSessionToken = _asyncToGenerator(function* (otpCallback, state) {
427
435
  (0, _Console.debugMessage)({
428
436
  message: "AuthenticateOps.getUserSessionToken: start",
429
437
  state
@@ -450,6 +458,7 @@ function _getUserSessionToken() {
450
458
  }
451
459
  if (!token) {
452
460
  token = yield getFreshUserSessionToken({
461
+ otpCallbackHandler: otpCallback,
453
462
  state
454
463
  });
455
464
  token.from_cache = false;
@@ -472,7 +481,7 @@ function _getUserSessionToken() {
472
481
  });
473
482
  return _getUserSessionToken.apply(this, arguments);
474
483
  }
475
- function getAuthCode(_x5, _x6, _x7, _x8) {
484
+ function getAuthCode(_x6, _x7, _x8, _x9) {
476
485
  return _getAuthCode.apply(this, arguments);
477
486
  }
478
487
  /**
@@ -502,17 +511,7 @@ function _getAuthCode() {
502
511
  } catch (error) {
503
512
  response = error.response;
504
513
  if (response.status < 200 || response.status > 399) {
505
- (0, _Console.printMessage)({
506
- message: 'error getting auth code',
507
- type: 'error',
508
- state
509
- });
510
- (0, _Console.printMessage)({
511
- message: response.data,
512
- type: 'error',
513
- state
514
- });
515
- return null;
514
+ throw error;
516
515
  }
517
516
  }
518
517
  var redirectLocationURL = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.location;
@@ -520,34 +519,14 @@ function _getAuthCode() {
520
519
  if ('code' in queryObject) {
521
520
  return queryObject.code;
522
521
  }
523
- (0, _Console.printMessage)({
524
- message: 'auth code not found',
525
- type: 'error',
526
- state
527
- });
528
- return null;
522
+ throw new _FrodoError.FrodoError("Authz code not found");
529
523
  } catch (error) {
530
- var _error$response;
531
- (0, _Console.printMessage)({
532
- message: "error getting auth code - ".concat(error.message),
533
- type: 'error',
534
- state
535
- });
536
- (0, _Console.printMessage)({
537
- message: (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data,
538
- type: 'error',
539
- state
540
- });
541
- (0, _Console.debugMessage)({
542
- message: error.stack,
543
- state
544
- });
545
- return null;
524
+ throw new _FrodoError.FrodoError("Error getting authz code", error);
546
525
  }
547
526
  });
548
527
  return _getAuthCode.apply(this, arguments);
549
528
  }
550
- function getFreshUserBearerToken(_x9) {
529
+ function getFreshUserBearerToken(_x10) {
551
530
  return _getFreshUserBearerToken.apply(this, arguments);
552
531
  }
553
532
  /**
@@ -556,10 +535,10 @@ function getFreshUserBearerToken(_x9) {
556
535
  * @returns {Promise<AccessTokenMetaType>} access token or null
557
536
  */
558
537
  function _getFreshUserBearerToken() {
559
- _getFreshUserBearerToken = _asyncToGenerator(function* (_ref2) {
538
+ _getFreshUserBearerToken = _asyncToGenerator(function* (_ref3) {
560
539
  var {
561
540
  state
562
- } = _ref2;
541
+ } = _ref3;
563
542
  (0, _Console.debugMessage)({
564
543
  message: "AuthenticateOps.getAccessTokenForUser: start",
565
544
  state
@@ -570,14 +549,6 @@ function _getFreshUserBearerToken() {
570
549
  var challengeMethod = 'S256';
571
550
  var redirectURL = _url.default.resolve(state.getHost(), redirectUrlTemplate);
572
551
  var authCode = yield getAuthCode(redirectURL, challenge, challengeMethod, state);
573
- if (authCode == null) {
574
- (0, _Console.printMessage)({
575
- message: 'error getting auth code',
576
- type: 'error',
577
- state
578
- });
579
- return null;
580
- }
581
552
  var response = null;
582
553
  if (state.getDeploymentType() === _Constants.default.CLOUD_DEPLOYMENT_TYPE_KEY) {
583
554
  var config = {
@@ -609,31 +580,14 @@ function _getFreshUserBearerToken() {
609
580
  });
610
581
  return response;
611
582
  }
612
- (0, _Console.printMessage)({
613
- message: 'No access token in response.',
614
- type: 'error',
615
- state
616
- });
583
+ throw new _FrodoError.FrodoError("No access token in response");
617
584
  } catch (error) {
618
- var _error$response2;
619
- (0, _Console.debugMessage)({
620
- message: "Error getting access token for user: ".concat(error),
621
- state
622
- });
623
- (0, _Console.debugMessage)({
624
- message: (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data,
625
- state
626
- });
585
+ throw new _FrodoError.FrodoError("Error getting access token for user", error);
627
586
  }
628
- (0, _Console.debugMessage)({
629
- message: "AuthenticateOps.getAccessTokenForUser: end without token",
630
- state
631
- });
632
- return null;
633
587
  });
634
588
  return _getFreshUserBearerToken.apply(this, arguments);
635
589
  }
636
- function getUserBearerToken(_x10) {
590
+ function getUserBearerToken(_x11) {
637
591
  return _getUserBearerToken.apply(this, arguments);
638
592
  }
639
593
  function _getUserBearerToken() {
@@ -710,7 +664,7 @@ function createPayload(serviceAccountId, host) {
710
664
  * @param {State} state library state
711
665
  * @returns {Promise<AccessTokenResponseType>} response object containg token, scope, type, and expiration in seconds
712
666
  */
713
- function getFreshSaBearerToken(_x11) {
667
+ function getFreshSaBearerToken(_x12) {
714
668
  return _getFreshSaBearerToken.apply(this, arguments);
715
669
  }
716
670
  /**
@@ -719,12 +673,12 @@ function getFreshSaBearerToken(_x11) {
719
673
  * @returns {Promise<AccessTokenResponseType>} response object containg token, scope, type, and expiration in seconds
720
674
  */
721
675
  function _getFreshSaBearerToken() {
722
- _getFreshSaBearerToken = _asyncToGenerator(function* (_ref3) {
676
+ _getFreshSaBearerToken = _asyncToGenerator(function* (_ref4) {
723
677
  var {
724
678
  saId = undefined,
725
679
  saJwk = undefined,
726
680
  state
727
- } = _ref3;
681
+ } = _ref4;
728
682
  (0, _Console.debugMessage)({
729
683
  message: "AuthenticateOps.getFreshSaBearerToken: start",
730
684
  state
@@ -755,7 +709,7 @@ function _getFreshSaBearerToken() {
755
709
  });
756
710
  return _getFreshSaBearerToken.apply(this, arguments);
757
711
  }
758
- function getSaBearerToken(_x12) {
712
+ function getSaBearerToken(_x13) {
759
713
  return _getSaBearerToken.apply(this, arguments);
760
714
  }
761
715
  /**
@@ -763,10 +717,10 @@ function getSaBearerToken(_x12) {
763
717
  * @param state library state
764
718
  */
765
719
  function _getSaBearerToken() {
766
- _getSaBearerToken = _asyncToGenerator(function* (_ref4) {
720
+ _getSaBearerToken = _asyncToGenerator(function* (_ref5) {
767
721
  var {
768
722
  state
769
- } = _ref4;
723
+ } = _ref5;
770
724
  (0, _Console.debugMessage)({
771
725
  message: "AuthenticateOps.getSaBearerToken: start",
772
726
  state
@@ -811,7 +765,7 @@ function _getSaBearerToken() {
811
765
  });
812
766
  return _getSaBearerToken.apply(this, arguments);
813
767
  }
814
- function determineDeploymentTypeAndDefaultRealmAndVersion(_x13) {
768
+ function determineDeploymentTypeAndDefaultRealmAndVersion(_x14) {
815
769
  return _determineDeploymentTypeAndDefaultRealmAndVersion.apply(this, arguments);
816
770
  }
817
771
  /**
@@ -849,7 +803,7 @@ function _determineDeploymentTypeAndDefaultRealmAndVersion() {
849
803
  });
850
804
  return _determineDeploymentTypeAndDefaultRealmAndVersion.apply(this, arguments);
851
805
  }
852
- function getLoggedInSubject(_x14) {
806
+ function getLoggedInSubject(_x15) {
853
807
  return _getLoggedInSubject.apply(this, arguments);
854
808
  }
855
809
  /**
@@ -912,35 +866,30 @@ function scheduleAutoRefresh(forceLoginAsUser, autoRefresh, state) {
912
866
  timer.unref();
913
867
  }
914
868
  }
915
-
916
869
  /**
917
870
  * Get tokens
918
871
  * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false)
919
872
  * @param {boolean} autoRefresh true to automatically refresh tokens before they expire (default: true)
920
873
  * @param {State} state library state
921
- * @returns {Promise<boolean>} true if tokens were successfully obtained, false otherwise
874
+ * @returns {Promise<Tokens>} object containing the tokens
922
875
  */
923
- function getTokens(_x15) {
876
+ function getTokens(_x16) {
924
877
  return _getTokens.apply(this, arguments);
925
878
  }
926
879
  function _getTokens() {
927
- _getTokens = _asyncToGenerator(function* (_ref5) {
880
+ _getTokens = _asyncToGenerator(function* (_ref6) {
928
881
  var {
929
882
  forceLoginAsUser = false,
930
883
  autoRefresh = true,
884
+ callbackHandler = null,
931
885
  state
932
- } = _ref5;
886
+ } = _ref6;
933
887
  (0, _Console.debugMessage)({
934
888
  message: "AuthenticateOps.getTokens: start",
935
889
  state
936
890
  });
937
891
  if (!state.getHost()) {
938
- (0, _Console.printMessage)({
939
- message: "No host specified and FRODO_HOST env variable not set!",
940
- type: 'error',
941
- state
942
- });
943
- return false;
892
+ throw new _FrodoError.FrodoError("No host specified");
944
893
  }
945
894
  try {
946
895
  // if username/password on cli are empty, try to read from connections.json
@@ -958,7 +907,7 @@ function _getTokens() {
958
907
  state.setServiceAccountId(conn.svcacctId);
959
908
  state.setServiceAccountJwk(conn.svcacctJwk);
960
909
  } else {
961
- return false;
910
+ throw new _FrodoError.FrodoError("No credentials specified and no connection profile found for ".concat(state.getHost()));
962
911
  }
963
912
  }
964
913
 
@@ -971,7 +920,7 @@ function _getTokens() {
971
920
  state.setHost(_conn.tenant);
972
921
  state.setDeploymentType(_conn.deploymentType);
973
922
  } else {
974
- return false;
923
+ throw new _FrodoError.FrodoError("No connection profile found for ".concat(state.getHost()));
975
924
  }
976
925
  }
977
926
 
@@ -992,7 +941,7 @@ function _getTokens() {
992
941
  state.setUseBearerTokenForAmApis(true);
993
942
  yield determineDeploymentTypeAndDefaultRealmAndVersion(state);
994
943
  } catch (saErr) {
995
- var _saErr$response, _saErr$response2, _saErr$response3;
944
+ var _saErr$response;
996
945
  (0, _Console.debugMessage)({
997
946
  message: ((_saErr$response = saErr.response) === null || _saErr$response === void 0 ? void 0 : _saErr$response.data) || saErr,
998
947
  state
@@ -1001,7 +950,7 @@ function _getTokens() {
1001
950
  message: state.getState(),
1002
951
  state
1003
952
  });
1004
- throw new Error("Service account login error: ".concat(((_saErr$response2 = saErr.response) === null || _saErr$response2 === void 0 || (_saErr$response2 = _saErr$response2.data) === null || _saErr$response2 === void 0 ? void 0 : _saErr$response2.error_description) || ((_saErr$response3 = saErr.response) === null || _saErr$response3 === void 0 || (_saErr$response3 = _saErr$response3.data) === null || _saErr$response3 === void 0 ? void 0 : _saErr$response3.message) || saErr));
953
+ throw new _FrodoError.FrodoError("Service account login error", saErr);
1005
954
  }
1006
955
  }
1007
956
  // use user account to login
@@ -1010,7 +959,7 @@ function _getTokens() {
1010
959
  message: "AuthenticateOps.getTokens: Authenticating with user account ".concat(state.getUsername()),
1011
960
  state
1012
961
  });
1013
- var _token = yield getUserSessionToken(state);
962
+ var _token = yield getUserSessionToken(callbackHandler, state);
1014
963
  if (_token) state.setUserSessionTokenMeta(_token);
1015
964
  yield determineDeploymentTypeAndDefaultRealmAndVersion(state);
1016
965
  if (state.getCookieValue() && (
@@ -1022,12 +971,7 @@ function _getTokens() {
1022
971
  }
1023
972
  // incomplete or no credentials
1024
973
  else {
1025
- (0, _Console.printMessage)({
1026
- message: "Incomplete or no credentials!",
1027
- type: 'error',
1028
- state
1029
- });
1030
- return false;
974
+ throw new _FrodoError.FrodoError("Incomplete or no credentials");
1031
975
  }
1032
976
  if (state.getCookieValue() || state.getUseBearerTokenForAmApis() && state.getBearerToken()) {
1033
977
  var _state$getBearerToken3, _state$getUserSession3;
@@ -1043,54 +987,24 @@ function _getTokens() {
1043
987
  state
1044
988
  });
1045
989
  }
1046
- (0, _Console.printMessage)({
1047
- message: "Connected to ".concat(state.getHost(), " [").concat(state.getRealm() ? state.getRealm() : 'root', "] as ").concat(yield getLoggedInSubject(state)),
1048
- type: 'info',
1049
- state
1050
- });
1051
990
  scheduleAutoRefresh(forceLoginAsUser, autoRefresh, state);
991
+ var tokens = {
992
+ bearerToken: state.getBearerTokenMeta(),
993
+ userSessionToken: state.getUserSessionTokenMeta(),
994
+ subject: yield getLoggedInSubject(state),
995
+ host: state.getHost(),
996
+ realm: state.getRealm() ? state.getRealm() : 'root'
997
+ };
1052
998
  (0, _Console.debugMessage)({
1053
999
  message: "AuthenticateOps.getTokens: end with tokens",
1054
1000
  state
1055
1001
  });
1056
- return true;
1002
+ // `Connected to ${state.getHost()} [${state.getRealm() ? state.getRealm() : 'root'}] as ${await getLoggedInSubject(state)}`
1003
+ return tokens;
1057
1004
  }
1058
1005
  } catch (error) {
1059
- var _error$response3, _error$response4, _error$response5;
1060
- // regular error
1061
- (0, _Console.printMessage)({
1062
- message: error.message,
1063
- type: 'error',
1064
- state
1065
- });
1066
- // axios error am api
1067
- (0, _Console.printMessage)({
1068
- message: (_error$response3 = error.response) === null || _error$response3 === void 0 || (_error$response3 = _error$response3.data) === null || _error$response3 === void 0 ? void 0 : _error$response3.message,
1069
- type: 'error',
1070
- state
1071
- });
1072
- // axios error am oauth2 api
1073
- (0, _Console.printMessage)({
1074
- message: (_error$response4 = error.response) === null || _error$response4 === void 0 || (_error$response4 = _error$response4.data) === null || _error$response4 === void 0 ? void 0 : _error$response4.error_description,
1075
- type: 'error',
1076
- state
1077
- });
1078
- // axios error data
1079
- (0, _Console.debugMessage)({
1080
- message: (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : _error$response5.data,
1081
- state
1082
- });
1083
- // stack trace
1084
- (0, _Console.debugMessage)({
1085
- message: error.stack || new Error().stack,
1086
- state
1087
- });
1006
+ throw new _FrodoError.FrodoError("Error getting tokens", error);
1088
1007
  }
1089
- (0, _Console.debugMessage)({
1090
- message: "AuthenticateOps.getTokens: end without tokens",
1091
- state
1092
- });
1093
- return false;
1094
1008
  });
1095
1009
  return _getTokens.apply(this, arguments);
1096
1010
  }