@rockcarver/frodo-lib
Version:
A library to manage ForgeRock Identity Cloud tenants, ForgeOps deployments, and classic deployments.
390 lines (379 loc) • 60.2 kB
HTML
<!DOCTYPE html><html class="default" lang="en" data-base="."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Frodo Library - v3.1.0</title><meta name="description" content="Documentation for Frodo Library"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script><script async src="assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"><a href="https://github.com/rockcarver/frodo-lib">Project Home</a></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">Frodo Library - v3.1.0</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>Frodo Library - v3.1.0</h1></div><div class="tsd-panel tsd-typography"><!-- README.md for GitHub; the one for NPM is ../README.md. -->
<a id="frodo-library-2x---rockcarverfrodo-lib" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Frodo Library 2.x - @rockcarver/frodo-lib<a href="#frodo-library-2x---rockcarverfrodo-lib" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p>A hybrid (ESM and CJS) library to manage PingOne Advanced Identity Cloud environments, ForgeOps deployments, and classic deployments.</p>
<p>Frodo-lib powers <a href="https://github.com/rockcarver/frodo-cli">frodo-cli</a>, the command line tool to manage ForgeRock deployments.</p>
<a id="quick-nav" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Quick Nav<a href="#quick-nav" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
<li><a href="#new-in-2x">New in 2.x</a></li>
<li><a href="#considerations">Considerations</a></li>
<li><a href="#installing">Installing</a></li>
<li><a href="#using-the-library">Using the library</a></li>
<li><a href="#library-api-docs">Library API docs</a></li>
<li><a href="#feature-requests">Request features or report issues</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#maintaining">Maintaining</a></li>
</ul>
<a id="new-in-2x" class="tsd-anchor"></a><h2 class="tsd-anchor-link">New In 2.x<a href="#new-in-2x" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="multi-instantiability" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Multi-Instantiability<a href="#multi-instantiability" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>2.x introduces breaking changes to support multiple instances of the library to run concurrently and connect to multiple different Ping Identity Platform instances at the same time. <a href="https://github.com/rockcarver/frodo-lib/tree/1.x">1.x</a> operates using a global singleton, making it impossible to connect to more than one platform instance at a time.</p>
<a id="new-library-structure" class="tsd-anchor"></a><h3 class="tsd-anchor-link">New Library Structure<a href="#new-library-structure" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Removing the singleton pattern and introducing multi-instantiability forced a radical redesign of the core library functions while striving to maintain the basic usage pattern. The library is now exposing two main types describing its modules (<a href="https://rockcarver.github.io/frodo-lib/types/Reference.Frodo.html">Frodo</a>) and state (<a href="https://rockcarver.github.io/frodo-lib/types/Reference.State.html">State</a>). Each module in turn exports all its collection of functions as a type as well. Exposing the library structure as types enables auto-completion for both JS and TS developers with properly configured IDEs like Visual Studio Code or other and also serves as an abstraction layer between what the library exposes vs what and how it's implemented.</p>
<a id="new-frodoerror-class" class="tsd-anchor"></a><h4 class="tsd-anchor-link">New <code>FrodoError</code> Class<a href="#new-frodoerror-class" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h4><p>All the errors thrown by the library are of the class <code>FrodoError</code>, introduced in 2.x. The new error class addresses the following challenges of earlier library versions:</p>
<ul>
<li>
<p>Allows applications using the library to determine if the error originated in the library or is an unexpected and unhandled error from deeper down the stack.</p>
</li>
<li>
<p>Nesting of errors:</p>
<p>When the library throws because it caught an error thrown deeper down the stack, it wraps the caught <code>Error</code> in a <code>FrodoError</code>.</p>
</li>
<li>
<p>Nesting of arrays of errors</p>
<p>The library supports many operation that require a number of actions to occur in a row or in parallel. Often these operations are REST API calls and any of those calls may fail for any reason. To preserve status of every operation, <code>FrodoError</code> can also wrap an array of errors, each of which may be another instance of <code>FrodoError</code> wrapping an individual or an array of errors.</p>
</li>
<li>
<p>Provides a stack-like combined error message concatenating the messages of all wrapped errors and nested errors.</p>
</li>
<li>
<p>Includes standardized fields to surface network errors in case the <code>Error</code> on top of the stack is an <code>AxiosError</code>.</p>
</li>
<li>
<p>The new <code>printError</code> function recognizes <code>FrodoError</code> and prints a uniformly formatted expression of the error including an interpretation of the fields for network stack errors.</p>
</li>
</ul>
<a id="new-modules" class="tsd-anchor"></a><h3 class="tsd-anchor-link">New Modules<a href="#new-modules" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The following modules have been updated and/or added since <a href="https://github.com/rockcarver/frodo-lib/tree/1.x">1.x</a>:</p>
<table>
<thead>
<tr>
<th>Module</th>
<th>Since</th>
<th>Capabilities</th>
</tr>
</thead>
<tbody>
<tr>
<td>frodo.admin</td>
<td>1.0.0</td>
<td>Library of common and complex admin tasks.</td>
</tr>
<tr>
<td>frodo.agent</td>
<td>1.0.0</td>
<td>Manage web, java, and gateway agents.</td>
</tr>
<tr>
<td>frodo.app</td>
<td>2.0.0</td>
<td>Manage platform applications and dependencies.</td>
</tr>
<tr>
<td>frodo.authn.journey</td>
<td>1.0.0</td>
<td>Manage authentication journeys.</td>
</tr>
<tr>
<td>frodo.authn.node</td>
<td>1.0.0</td>
<td>Manage authentication nodes.</td>
</tr>
<tr>
<td>frodo.authn.settings</td>
<td>2.0.0</td>
<td>Manage realm-wide authentication settings.</td>
</tr>
<tr>
<td>frodo.authz.policy</td>
<td>1.0.0</td>
<td>Manage authorization policies and dependencies.</td>
</tr>
<tr>
<td>frodo.authz.policySet</td>
<td>1.0.0</td>
<td>Manage policy sets and dependencies.</td>
</tr>
<tr>
<td>frodo.authz.resourceType</td>
<td>1.0.0</td>
<td>Manage resource types and dependencies.</td>
</tr>
<tr>
<td>frodo.cache</td>
<td>2.0.0</td>
<td>Token cache management exposed through the library but primarily used internally.</td>
</tr>
<tr>
<td>frodo.cloud.adminFed</td>
<td>1.0.0</td>
<td>Manage PingOne Advanced Identity Cloud admin federation.</td>
</tr>
<tr>
<td>frodo.cloud.feature</td>
<td>1.0.0</td>
<td>Obtain info on PingOne Advanced Identity Cloud features.</td>
</tr>
<tr>
<td>frodo.cloud.log</td>
<td>1.0.0</td>
<td>Access PingOne Advanced Identity Cloud debug and audit logs.</td>
</tr>
<tr>
<td>frodo.cloud.secret</td>
<td>1.0.0</td>
<td>Mange secrets in PingOne Advanced Identity Cloud.</td>
</tr>
<tr>
<td>frodo.cloud.serviceAccount</td>
<td>1.0.0</td>
<td>Manage service accounts in PingOne Advanced Identity Cloud.</td>
</tr>
<tr>
<td>frodo.cloud.startup</td>
<td>1.0.0</td>
<td>Apply changes to secrets and variables and restart services in PingOne Advanced Identity Cloud.</td>
</tr>
<tr>
<td>frodo.cloud.variable</td>
<td>1.0.0</td>
<td>Manage variables in PingOne Advanced Identity Cloud.</td>
</tr>
<tr>
<td>frodo.conn</td>
<td>1.0.0</td>
<td>Manage connection profiles.</td>
</tr>
<tr>
<td>frodo.config</td>
<td>2.0.0</td>
<td>Manage the whole platform configuration.</td>
</tr>
<tr>
<td>frodo.email.template</td>
<td>1.0.0</td>
<td>Manage email templates (IDM).</td>
</tr>
<tr>
<td>frodo.idm.config</td>
<td>2.0.0</td>
<td>Manage any IDM configuration object.</td>
</tr>
<tr>
<td>frodo.idm.connector</td>
<td>2.0.0</td>
<td>Manage IDM connector configuration.</td>
</tr>
<tr>
<td>frodo.idm.managed</td>
<td>1.0.0</td>
<td>Manage IDM managed object schema (managed.json).</td>
</tr>
<tr>
<td>frodo.idm.mapping</td>
<td>2.0.0</td>
<td>Manage IDM mappings (sync.json).</td>
</tr>
<tr>
<td>frodo.idm.organization</td>
<td>1.0.0</td>
<td>Limited Org Model management exposed through the library but primarily used internally.</td>
</tr>
<tr>
<td>frodo.idm.recon</td>
<td>2.0.0</td>
<td>Read, start, cancel IDM recons.</td>
</tr>
<tr>
<td>frodo.idm.system</td>
<td>2.0.0</td>
<td>Manage data in connected systems.</td>
</tr>
<tr>
<td><a href="http://frodo.info">frodo.info</a></td>
<td>1.0.0</td>
<td>Obtain information about the connected instance and authenticated identity.</td>
</tr>
<tr>
<td>frodo.login</td>
<td>1.0.0</td>
<td>Authenticate and obtain necessary tokens.</td>
</tr>
<tr>
<td>frodo.oauth2oidc.client</td>
<td>1.0.0</td>
<td>Manage OAuth 2.0 clients.</td>
</tr>
<tr>
<td>frodo.oauth2oidc.endpoint</td>
<td>2.0.0</td>
<td>Limited OAuth 2.0 grant flows exposed through the library but primarily used internally.</td>
</tr>
<tr>
<td>frodo.oauth2oidc.external</td>
<td>1.0.0</td>
<td>Manage external OAuth 2.0/OIDC 1.0 (social) identity providers.</td>
</tr>
<tr>
<td>frodo.oauth2oidc.issuer</td>
<td>2.0.0</td>
<td>Manage trusted OAuth 2.0 JWT issuers.</td>
</tr>
<tr>
<td>frodo.oauth2oidc.provider</td>
<td>1.0.0</td>
<td>Manage the realm OAuth 2.0 provider.</td>
</tr>
<tr>
<td>frodo.realm</td>
<td>1.0.0</td>
<td>Manage realms.</td>
</tr>
<tr>
<td>frodo.saml.circlesOfTrust</td>
<td>1.0.0</td>
<td>Manage SAML 2.0 circles of trust.</td>
</tr>
<tr>
<td>frodo.saml.entityProvider</td>
<td>1.0.0</td>
<td>Manage SAML 2.0 entity providers.</td>
</tr>
<tr>
<td>frodo.script</td>
<td>1.0.0</td>
<td>Manage access management scripts.</td>
</tr>
<tr>
<td>frodo.service</td>
<td>1.0.0</td>
<td>Manage access management services.</td>
</tr>
<tr>
<td>frodo.session</td>
<td>2.0.0</td>
<td>Limited session management exposed through the library but primarily used internally.</td>
</tr>
<tr>
<td>frodo.state</td>
<td>1.0.0</td>
<td>Manage library state.</td>
</tr>
<tr>
<td>frodo.theme</td>
<td>1.0.0</td>
<td>Manage platform themes (hosted pages).</td>
</tr>
<tr>
<td>frodo.utils.constants</td>
<td>1.0.0</td>
<td>Access relevant library constants.</td>
</tr>
<tr>
<td>frodo.utils.jose</td>
<td>1.0.0</td>
<td>Jose utility functions exposed through the library but primarily used internally.</td>
</tr>
<tr>
<td>frodo.utils.json</td>
<td>1.0.0</td>
<td>JSON utility functions exposed through the library but primarily used internally.</td>
</tr>
<tr>
<td>frodo.utils.version</td>
<td>1.0.0</td>
<td>Utility functions to obtain current library version and available released versions.</td>
</tr>
</tbody>
</table>
<a id="secure-token-caching" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Secure Token Caching<a href="#secure-token-caching" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The 2.x version of the library uses a secure token cache, which is active by default. The cache makes it so that when the <code>frodo.login.getTokens()</code> method is called, available tokens are updated in <code>state</code> from cache and if none are available, they are obtained from the instance configured in <code>state</code>. The cache is tokenized and encrypted on disk, so it persists across library instantiations. You can disable the cache by either setting the <code>FRODO_NO_CACHE</code> environment variable or by calling <code>state.setUseTokenCache(false)</code> from your application.
You can change the default location of the cache file (<code>~/.frodo/TokenCache.json</code>) by either setting the <code>FRODO_TOKEN_CACHE_PATH</code> environment variable or by calling <code>state.setTokenCachePath('/path/to/cache.json')</code>.</p>
<a id="automatic-token-refresh" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Automatic Token Refresh<a href="#automatic-token-refresh" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The 2.x version of the library automatically refreshes session and access tokens before they expire. Combined with the new token cache, the library will maintain a set of valid tokens in <code>state</code> at all times until it is shut down. If you do not want to automatically refresh tokens, set the <code>autoRefresh</code> parameter (2nd param) of your <code>frodo.login.getTokens()</code> call to <code>false</code>.</p>
<a id="nodejs-versions" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Node.js Versions<a href="#nodejs-versions" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><ul>
<li>Dropped support for Node.js 14 and 16.</li>
<li>Kept supporting Node.js 18.</li>
<li>Added support for Node.js 20 and 22.</li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:center">Node.js</th>
<th style="text-align:center">frodo-lib 1.x</th>
<th style="text-align:center"><em><strong>frodo-lib 2.x</strong></em></th>
<th style="text-align:center">frodo-lib 3.x</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">14</td>
<td style="text-align:center">:white_check_mark:</td>
<td style="text-align:center">:heavy_minus_sign:</td>
<td style="text-align:center">:heavy_minus_sign:</td>
</tr>
<tr>
<td style="text-align:center">16</td>
<td style="text-align:center">:white_check_mark:</td>
<td style="text-align:center">:heavy_minus_sign:</td>
<td style="text-align:center">:heavy_minus_sign:</td>
</tr>
<tr>
<td style="text-align:center">18</td>
<td style="text-align:center">:white_check_mark:</td>
<td style="text-align:center">:white_check_mark:</td>
<td style="text-align:center">:heavy_minus_sign:</td>
</tr>
<tr>
<td style="text-align:center">20</td>
<td style="text-align:center">:heavy_minus_sign:</td>
<td style="text-align:center">:white_check_mark:</td>
<td style="text-align:center">:white_check_mark:</td>
</tr>
<tr>
<td style="text-align:center">22</td>
<td style="text-align:center">:heavy_minus_sign:</td>
<td style="text-align:center">:white_check_mark:</td>
<td style="text-align:center">:white_check_mark:</td>
</tr>
<tr>
<td style="text-align:center">24</td>
<td style="text-align:center">:heavy_minus_sign:</td>
<td style="text-align:center">:heavy_minus_sign:</td>
<td style="text-align:center">:white_check_mark:</td>
</tr>
</tbody>
</table>
<a id="considerations" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Considerations<a href="#considerations" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="platform-passwords-and-secrets" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Platform Passwords And Secrets<a href="#platform-passwords-and-secrets" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Platform passwords and secrets are configuration values that are stored encrypted as part of platform configuration. Examples are oauth2 client secrets or service account passwords.</p>
<p>Frodo generally doesn't export platform passwords and secrets. The platform supports configuration placeholders and environment secrets and variables allowing administrators to separate the functional configuration from sensitive secrets and variable configuration values. <code>frodo</code> assumes administrators take full advantage of these capabilities so that there is no need or expectation that exports include passwords and secrets. However, where the APIs support it, administrators can seed import data with raw secrets and <code>frodo</code> will import them.</p>
<a id="advanced-identity-cloud-environment-secrets-and-variables-esvs" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Advanced Identity Cloud Environment Secrets And Variables (ESVs)<a href="#advanced-identity-cloud-environment-secrets-and-variables-esvs" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Frodo supports exporting and importing of ESV secret values. To leave stuartship of secret values with the cloud environment where they belong, frodo always encrypts values using either encryption keys from the source environment (default) or the target environment. Frodo never exports secrets in the clear.</p>
<a id="installing" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Installing<a href="#installing" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="developer-mode" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Developer Mode<a href="#developer-mode" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>For those who want to contribute or are just curious about the build process.</p>
<ul>
<li>Make sure you have <strong>Node.js 18</strong> or newer (<strong>20</strong> or <strong>22</strong> preferred) and npm installed.</li>
<li>Clone this repo<pre><code class="console"><span class="hl-0">git clone https://github.com/rockcarver/frodo-lib.git</span>
</code><button type="button">Copy</button></pre>
</li>
<li>Install dependencies via NPM<pre><code class="console"><span class="hl-0">cd frodo-lib</span><br/><span class="hl-0">npm ci</span>
</code><button type="button">Copy</button></pre>
</li>
</ul>
<a id="npm-package" class="tsd-anchor"></a><h3 class="tsd-anchor-link">NPM package<a href="#npm-package" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>If you are a node developer and want to use frodo-lib as a library for your own applications, you can install the npm package:</p>
<ul>
<li>To install the latest version as a dependency for you own application:<pre><code class="console"><span class="hl-0">npm i @rockcarver/frodo-lib</span>
</code><button type="button">Copy</button></pre>
</li>
<li>To install the latest pre-release:<pre><code class="console"><span class="hl-0">npm i @rockcarver/frodo-lib@next</span>
</code><button type="button">Copy</button></pre>
</li>
</ul>
<a id="using-the-library" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Using the library<a href="#using-the-library" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="import-the-library-members-esm" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Import the library members (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/esm/index.js#L1-L6">ESM</a>):<a href="#import-the-library-members-esm" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-1">import</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">// default instance</span><br/><span class="hl-0"> </span><span class="hl-3">frodo</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">// default state</span><br/><span class="hl-0"> </span><span class="hl-3">state</span><span class="hl-0">,</span><br/><span class="hl-0">} </span><span class="hl-1">from</span><span class="hl-0"> </span><span class="hl-4">'@rockcarver/frodo-lib'</span><span class="hl-0">;</span>
</code><button type="button">Copy</button></pre>
<a id="require-the-library-members-cjs" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Require the library members (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/cjs/index.js#L1-L6">CJS</a>):<a href="#require-the-library-members-cjs" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-5">const</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">// default instance</span><br/><span class="hl-0"> </span><span class="hl-6">frodo</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">// default state</span><br/><span class="hl-0"> </span><span class="hl-6">state</span><span class="hl-0">,</span><br/><span class="hl-0">} = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-4">'@rockcarver/frodo-lib'</span><span class="hl-0">);</span>
</code><button type="button">Copy</button></pre>
<a id="use-the-library" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Use the library<a href="#use-the-library" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Create a new instance using factory helper function and login as service account (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/esm/index.js#L24-L61">ESM</a> | <a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/cjs/index.js#L24-L61">CJS</a>):</p>
<pre><code class="javascript"><span class="hl-5">async</span><span class="hl-0"> </span><span class="hl-5">function</span><span class="hl-0"> </span><span class="hl-7">newFactoryHelperServiceAccountLogin</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">myFrodo1</span><span class="hl-0"> = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-7">createInstanceWithServiceAccount</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-3">host1</span><span class="hl-0">, </span><span class="hl-2">// host base URL</span><br/><span class="hl-0"> </span><span class="hl-3">said1</span><span class="hl-0">, </span><span class="hl-2">// service account id</span><br/><span class="hl-0"> </span><span class="hl-3">jwk1</span><span class="hl-0"> </span><span class="hl-2">// service account jwk as a string</span><br/><span class="hl-0"> );</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// destructure default instance for easier use of library functions</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getTokens</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo1</span><span class="hl-0">.</span><span class="hl-3">login</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getInfo</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo1</span><span class="hl-0">.</span><span class="hl-3">info</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// login and obtain tokens</span><br/><span class="hl-0"> </span><span class="hl-1">if</span><span class="hl-0"> (</span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getTokens</span><span class="hl-0">()) {</span><br/><span class="hl-0"> </span><span class="hl-2">// obtain and print information about the instance you are connected to</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">info</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getInfo</span><span class="hl-0">();</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryHelperServiceAccountLogin: Logged in to: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">host</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryHelperServiceAccountLogin: Logged in as: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">authenticatedSubject</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryHelperServiceAccountLogin: Using bearer token: </span><span class="hl-9">\n</span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">bearerToken</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> } </span><span class="hl-1">else</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">'error getting tokens'</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span><br/><span class="hl-0">}</span><br/><span class="hl-7">newFactoryHelperServiceAccountLogin</span><span class="hl-0">();</span>
</code><button type="button">Copy</button></pre>
<p>Create a new instance using factory helper function and login as admin user (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/esm/index.js#L63-L98">ESM</a> | <a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/cjs/index.js#L63-L98">CJS</a>):</p>
<pre><code class="javascript"><span class="hl-5">async</span><span class="hl-0"> </span><span class="hl-5">function</span><span class="hl-0"> </span><span class="hl-7">newFactoryHelperAdminLogin</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">myFrodo1</span><span class="hl-0"> = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-7">createInstanceWithAdminAccount</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-3">host1</span><span class="hl-0">, </span><span class="hl-2">// host base URL</span><br/><span class="hl-0"> </span><span class="hl-3">user1</span><span class="hl-0">, </span><span class="hl-2">// admin username</span><br/><span class="hl-0"> </span><span class="hl-3">pass1</span><span class="hl-0"> </span><span class="hl-2">// admin password</span><br/><span class="hl-0"> );</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// destructure default instance for easier use of library functions</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getTokens</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo1</span><span class="hl-0">.</span><span class="hl-3">login</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getInfo</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo1</span><span class="hl-0">.</span><span class="hl-3">info</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// login and obtain tokens</span><br/><span class="hl-0"> </span><span class="hl-1">if</span><span class="hl-0"> (</span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getTokens</span><span class="hl-0">()) {</span><br/><span class="hl-0"> </span><span class="hl-2">// obtain and print information about the instance you are connected to</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">info</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getInfo</span><span class="hl-0">();</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">`newFactoryHelperAdminLogin: Logged in to: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">host</span><span class="hl-5">}</span><span class="hl-4">`</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryHelperAdminLogin: Logged in as: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">authenticatedSubject</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryHelperAdminLogin: Using bearer token: </span><span class="hl-9">\n</span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">bearerToken</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> } </span><span class="hl-1">else</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">'error getting tokens'</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span><br/><span class="hl-0">}</span><br/><span class="hl-7">newFactoryHelperAdminLogin</span><span class="hl-0">();</span>
</code><button type="button">Copy</button></pre>
<p>Create a new instance using factory function and login as service account (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/esm/index.js#L100-L135">ESM</a> | <a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/cjs/index.js#L100-L135">CJS</a>):</p>
<pre><code class="javascript"><span class="hl-5">async</span><span class="hl-0"> </span><span class="hl-5">function</span><span class="hl-0"> </span><span class="hl-7">newFactoryServiceAccountLogin</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">myFrodo2</span><span class="hl-0"> = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-7">createInstance</span><span class="hl-0">({</span><br/><span class="hl-0"> </span><span class="hl-3">host:</span><span class="hl-0"> </span><span class="hl-3">host2</span><span class="hl-0">, </span><span class="hl-2">// host base URL</span><br/><span class="hl-0"> </span><span class="hl-3">serviceAccountId:</span><span class="hl-0"> </span><span class="hl-3">said2</span><span class="hl-0">, </span><span class="hl-2">// service account id</span><br/><span class="hl-0"> </span><span class="hl-3">serviceAccountJwk:</span><span class="hl-0"> </span><span class="hl-6">JSON</span><span class="hl-0">.</span><span class="hl-7">parse</span><span class="hl-0">(</span><span class="hl-3">jwk2</span><span class="hl-0">), </span><span class="hl-2">// service account jwk as a JwkRsa object</span><br/><span class="hl-0"> });</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// destructure default instance for easier use of library functions</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getTokens</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo2</span><span class="hl-0">.</span><span class="hl-3">login</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getInfo</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo2</span><span class="hl-0">.</span><span class="hl-3">info</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// login and obtain tokens</span><br/><span class="hl-0"> </span><span class="hl-1">if</span><span class="hl-0"> (</span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getTokens</span><span class="hl-0">()) {</span><br/><span class="hl-0"> </span><span class="hl-2">// obtain and print information about the instance you are connected to</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">info</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getInfo</span><span class="hl-0">();</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">`newFactoryServiceAccountLogin: Logged in to: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">host</span><span class="hl-5">}</span><span class="hl-4">`</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryServiceAccountLogin: Logged in as: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">authenticatedSubject</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryServiceAccountLogin: Using bearer token: </span><span class="hl-9">\n</span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">bearerToken</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> } </span><span class="hl-1">else</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">'error getting tokens'</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span><br/><span class="hl-0">}</span><br/><span class="hl-7">newFactoryServiceAccountLogin</span><span class="hl-0">();</span>
</code><button type="button">Copy</button></pre>
<p>Create a new instance using factory function and login as admin user (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/esm/index.js#L137-L168">ESM</a> | <a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/cjs/index.js#L137-L168">CJS</a>):</p>
<pre><code class="javascript"><span class="hl-5">async</span><span class="hl-0"> </span><span class="hl-5">function</span><span class="hl-0"> </span><span class="hl-7">newFactoryAdminLogin</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">myFrodo2</span><span class="hl-0"> = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-7">createInstance</span><span class="hl-0">({</span><br/><span class="hl-0"> </span><span class="hl-3">host:</span><span class="hl-0"> </span><span class="hl-3">host2</span><span class="hl-0">, </span><span class="hl-2">// host base URL</span><br/><span class="hl-0"> </span><span class="hl-3">username:</span><span class="hl-0"> </span><span class="hl-3">user2</span><span class="hl-0">, </span><span class="hl-2">// admin username</span><br/><span class="hl-0"> </span><span class="hl-3">password:</span><span class="hl-0"> </span><span class="hl-3">pass2</span><span class="hl-0">, </span><span class="hl-2">// admin password</span><br/><span class="hl-0"> });</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// destructure default instance for easier use of library functions</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getTokens</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo2</span><span class="hl-0">.</span><span class="hl-3">login</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getInfo</span><span class="hl-0"> } = </span><span class="hl-3">myFrodo2</span><span class="hl-0">.</span><span class="hl-3">info</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// login and obtain tokens</span><br/><span class="hl-0"> </span><span class="hl-1">if</span><span class="hl-0"> (</span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getTokens</span><span class="hl-0">()) {</span><br/><span class="hl-0"> </span><span class="hl-2">// obtain and print information about the instance you are connected to</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">info</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getInfo</span><span class="hl-0">();</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">`newFactoryAdminLogin: Logged in to: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">host</span><span class="hl-5">}</span><span class="hl-4">`</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryAdminLogin: Logged in as: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">authenticatedSubject</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`newFactoryAdminLogin: Using bearer token: </span><span class="hl-9">\n</span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">bearerToken</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> } </span><span class="hl-1">else</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">'error getting tokens'</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span><br/><span class="hl-0">}</span><br/><span class="hl-7">newFactoryAdminLogin</span><span class="hl-0">();</span>
</code><button type="button">Copy</button></pre>
<p>Use default instance and state and login as service account (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/esm/index.js#L170-L212">ESM</a> | <a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/cjs/index.js#L170-L212">CJS</a>):</p>
<pre><code class="javascript"><span class="hl-5">async</span><span class="hl-0"> </span><span class="hl-5">function</span><span class="hl-0"> </span><span class="hl-7">defaultServiceAccountLogin</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-2">// destructure default instance for easier use of library functions</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getTokens</span><span class="hl-0"> } = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-3">login</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getInfo</span><span class="hl-0"> } = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-3">info</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// The default state instance is a singleton. It is best to reset() the state before</span><br/><span class="hl-0"> </span><span class="hl-2">// logging in to avoid interference. In this particular case no previous method in</span><br/><span class="hl-0"> </span><span class="hl-2">// this file is using the default state but it is good practice to call reset() if</span><br/><span class="hl-0"> </span><span class="hl-2">// you are not sure and need a clean state.</span><br/><span class="hl-0"> </span><span class="hl-3">state</span><span class="hl-0">.</span><span class="hl-7">reset</span><span class="hl-0">();</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// host base URL</span><br/><span class="hl-0"> </span><span class="hl-3">state</span><span class="hl-0">.</span><span class="hl-7">setHost</span><span class="hl-0">(</span><span class="hl-3">host0</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">// service account id</span><br/><span class="hl-0"> </span><span class="hl-3">state</span><span class="hl-0">.</span><span class="hl-7">setServiceAccountId</span><span class="hl-0">(</span><span class="hl-3">said0</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">// service account jwk as a JwkRsa object</span><br/><span class="hl-0"> </span><span class="hl-3">state</span><span class="hl-0">.</span><span class="hl-7">setServiceAccountJwk</span><span class="hl-0">(</span><span class="hl-6">JSON</span><span class="hl-0">.</span><span class="hl-7">parse</span><span class="hl-0">(</span><span class="hl-3">jwk0</span><span class="hl-0">));</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// login and obtain tokens</span><br/><span class="hl-0"> </span><span class="hl-1">if</span><span class="hl-0"> (</span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getTokens</span><span class="hl-0">()) {</span><br/><span class="hl-0"> </span><span class="hl-2">// obtain and print information about the instance you are connected to</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">info</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">getInfo</span><span class="hl-0">();</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">`defaultServiceAccountLogin: Logged in to: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">host</span><span class="hl-5">}</span><span class="hl-4">`</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`defaultServiceAccountLogin: Logged in as: </span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">authenticatedSubject</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><br/><span class="hl-0"> </span><span class="hl-4">`defaultServiceAccountLogin: Using bearer token: </span><span class="hl-9">\n</span><span class="hl-5">${</span><span class="hl-3">info</span><span class="hl-8">.</span><span class="hl-3">bearerToken</span><span class="hl-5">}</span><span class="hl-4">`</span><br/><span class="hl-0"> );</span><br/><span class="hl-0"> } </span><span class="hl-1">else</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-3">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-4">'error getting tokens'</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span><br/><span class="hl-0">}</span><br/><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">defaultServiceAccountLogin</span><span class="hl-0">();</span>
</code><button type="button">Copy</button></pre>
<p>Use default instance and state and login as admin user (<a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/esm/index.js#L214-L250">ESM</a> | <a href="https://github.com/rockcarver/frodo-lib/blob/b7220de90478dfd3e1bb0d8b9cdcef455cb20b3b/examples/cjs/index.js#L214-L250">CJS</a>):</p>
<pre><code class="javascript"><span class="hl-5">async</span><span class="hl-0"> </span><span class="hl-5">function</span><span class="hl-0"> </span><span class="hl-7">defaultAdminLogin</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-2">// destructure default instance for easier use of library functions</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getTokens</span><span class="hl-0"> } = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-3">login</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> { </span><span class="hl-6">getInfo</span><span class="hl-0"> } = </span><span class="hl-3">frodo</span><span class="hl-0">.</span><span class="hl-3">info</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-2">// The default state instance is a singleton. It is best to reset() the state before</span><br/><span class="hl-0"> </span><span class="hl-2">// logging in to avoid interference. In this particular case the previous method in</span><br/><span cl