Skip to content

Connection

The connection cmdlets manage authentication and session state with a JIM instance. You must establish a connection with Connect-JIM before using any other JIM cmdlets. Use Test-JIMConnection to verify your session is active, and Disconnect-JIM to clean up when finished.

How Connect-JIM signs in Connect-JIM starts from the URL you give it. With -ApiKey, it checks that JIM accepts the key and connects with it, storing nothing. Without a key, it signs in interactively. If this PowerShell session already holds a single sign-on session with the same URL, and -Force is not given, it reuses that session, refreshing the access token if it is close to expiry. Otherwise, if the operating system's credential store holds a refresh token for the URL, and neither -Force nor -NoPersist is given, it connects silently using those cached credentials, with no browser. Failing that, it opens a browser to sign in, and saves the new refresh token to the credential store unless -NoPersist is given. yes no yes no yes no Connect-JIM -ApiKey given? Signed in to this URL already?by SSO; ignored with -Force Refresh token stored?ignored with -Force or -NoPersist Connected by API keykey checked; nothing stored Session reusedrefreshed if close to expiry Cached credentialsno browser sign-in Browser sign-intoken saved unless -NoPersist How Connect-JIM signs in Connect-JIM starts from the URL you give it. With -ApiKey, it checks that JIM accepts the key and connects with it, storing nothing. Without a key, it signs in interactively. If this PowerShell session already holds a single sign-on session with the same URL, and -Force is not given, it reuses that session, refreshing the access token if it is close to expiry. Otherwise, if the operating system's credential store holds a refresh token for the URL, and neither -Force nor -NoPersist is given, it connects silently using those cached credentials, with no browser. Failing that, it opens a browser to sign in, and saves the new refresh token to the credential store unless -NoPersist is given. yes no yes no yes no Connect-JIM -ApiKey given? Connected by API keykey checked; nothing stored Signed in to this URL already?by SSO; ignored with -Force Session reusedrefreshed if close to expiry Refresh token stored?ignored with -Force or -NoPersist Cached credentialsno browser sign-in Browser sign-intoken saved unless -NoPersist

Running a cmdlet before connecting

If you run any JIM cmdlet before Connect-JIM, it produces no output and reports a clear, non-terminating error telling you to connect first, for example:

Get-JIMConnectedSystem: You are not connected to JIM. Run Connect-JIM -Url <your JIM URL> to authenticate, then try again.

Because the error is non-terminating, a script continues by default. Add -ErrorAction Stop to the cmdlet (or set $ErrorActionPreference = 'Stop') when you want the not-connected state to halt the script or be caught by try/catch.


Connect-JIM

Establishes a connection to a JIM instance. This must be called before using any other JIM cmdlets.

Syntax

# Interactive (default)
Connect-JIM [-Url] <string> [-Force] [-NoPersist] [-TimeoutSeconds <int>]

# ApiKey
Connect-JIM [-Url] <string> [-ApiKey] <string>

Parameters

Name Type Required Default Description
Url string Yes The JIM instance's base URL, for example https://jim.example.com or http://localhost:5200. Can be given by position, as the first argument.
ApiKey string Yes (ApiKey) An API key, for non-interactive authentication; create one in the portal under Admin > API Keys. With a key, Connect-JIM does not open a browser, and never reads or writes the credential store. Connect-JIM checks that JIM accepts the key, and stops if it does not: a key JIM has no record of, or one that is disabled or has expired. An infrastructure key, set in JIM_INFRASTRUCTURE_API_KEY, exists only once JIM has started with it set, and expires 24 hours later; restarting JIM renews an expired one. Can be given by position, as the second argument.
Force switch No (Interactive) Signs in again even when a valid session exists, ignoring any persisted refresh token and overwriting it with the new one.
NoPersist switch No (Interactive) Signs in for this session only, without reading from or writing to the operating system's credential store. Useful on shared machines.
TimeoutSeconds int No (Interactive) 300 How long to wait, in seconds, for the browser sign-in to complete. From 30 to 600.

Output

The connection made.

Property Type Description
Url string The JIM instance's address.
AuthMethod string How the connection authenticated: OAuth or ApiKey.
Connected bool Always $true; a connection that fails throws instead.
ServerVersion string The JIM version the instance reported.
Authorised bool Whether the signed-in user has a JIM identity (a Metaverse Object) and so can use JIM; always $true for an API key.
Status string JIM's health status.
ExpiresAt datetime When the access token expires; OAuth only.
ApiKey string The key's first eight and last four characters; API key only.

Examples

Interactive SSO authentication
Connect-JIM -Url "https://jim.example.com"
Interactive SSO with forced re-authentication
Connect-JIM -Url "https://jim.example.com" -Force
Interactive SSO with custom timeout
Connect-JIM -Url "https://jim.example.com" -TimeoutSeconds 60
Interactive SSO without persisting the token (shared machine)
Connect-JIM -Url "https://jim.example.com" -NoPersist
API key authentication for automation
Connect-JIM -Url "https://jim.example.com" -ApiKey "jim_ak_7f3e..."
Using positional parameters
Connect-JIM "https://jim.example.com" "jim_ak_7f3e..."

Notes

  • Interactive SSO requires that SSO is configured on the JIM server, a browser is available on the local machine, and the identity provider permits localhost redirect URIs on the client it issues tokens to. The PowerShell module is a public OAuth client that uses PKCE with loopback redirects; on Keycloak, and any IdP where the web and interactive clients must be separate registrations, the JIM administrator must create a second public client and set JIM_SSO_PUBLIC_CLIENT_ID on the server; see SSO Setup for details.
  • API key authentication is recommended for automation, CI/CD pipelines, and headless environments where a browser is not available. Connect-JIM checks that JIM accepts the key, and stops with JIM rejected the API key when JIM has no record of it, or it is disabled or has expired; nothing is changed, so connect again with a valid key. An infrastructure key exists only once JIM has started with JIM_INFRASTRUCTURE_API_KEY set, and expires 24 hours later; restarting JIM renews an expired one.
  • OAuth sessions are cached locally; tokens are refreshed automatically when they approach expiry.
  • If a valid session already exists, Connect-JIM reuses it unless -Force is specified.
  • Token persistence (interactive SSO): after an interactive sign-in, the OAuth refresh token is saved to the operating system's credential store so that a new terminal can reconnect silently without opening a browser. The next Connect-JIM to the same URL prints Connected to JIM using cached credentials and skips the browser. Only the refresh token is stored, never the access token (a fresh access token is obtained from it on demand). The store used per platform is:

    Platform Credential store
    Windows Credential Manager (DPAPI, per-user)
    macOS login Keychain
    Linux libsecret (secret-tool), when present

    No password is required to unlock these stores beyond your normal OS sign-in. On systems with no usable store (typically headless Linux or SSH sessions without a keyring), persistence is skipped and the module prints a notice; use -ApiKey for unattended scenarios. Use -NoPersist to opt out of persistence for a session, and -Force to ignore and overwrite a persisted token. Persistence requires the identity provider to issue a refresh token, which depends on the offline_access scope being permitted on the public client (see SSO Setup). - To disconnect, use Disconnect-JIM. To verify your session, use Test-JIMConnection.


Disconnect-JIM

Disconnects from a JIM instance and forgets its persisted credentials.

Syntax

# Default
Disconnect-JIM [-Url <string>]

# All
Disconnect-JIM -All

Parameters

Name Type Required Default Description
Url string No (Default) The JIM instance to disconnect from and forget; the connected one when omitted. Works when not connected to it, since clearing the credential store does not need a session.
All switch Yes (All) Removes every persisted JIM refresh token from this machine, across all instances, and clears any session.

Output

None. Writes a message to the host saying what was removed.

Examples

Disconnect and forget the connected instance
Disconnect-JIM
Forget a specific instance's persisted token (even if not connected)
Disconnect-JIM -Url "https://jim.example.com"
Remove every persisted JIM token from this machine
Disconnect-JIM -All

Notes

  • Clears the in-memory session (access and refresh tokens) and removes the persisted refresh token for the targeted instance from the OS credential store, so a later Connect-JIM must authenticate again. By default the targeted instance is the connected one; use -Url for a specific instance or -All for every instance.
  • Removal is auth-agnostic: a stored refresh token for the instance is removed even if the cleared session authenticated with an API key. API keys themselves are never persisted by the module, so for an API-key-only session there is nothing in the store to remove.
  • -Url and -All work even when there is no active connection, since clearing the credential store is a maintenance operation independent of session state. A bare Disconnect-JIM while not connected has no instance to target and does nothing.
  • Does not sign you out of your identity provider. If you authenticated via SSO, your identity provider session remains active.
  • After disconnecting, you must call Connect-JIM again before using other JIM cmdlets.

Test-JIMConnection

Tests whether the current connection to a JIM instance is active and healthy.

Syntax

Test-JIMConnection [-Quiet]

Parameters

Name Type Required Default Description
Quiet switch No Returns only $true or $false instead of the connection's status.

Output

The connection's status; with -Quiet, $true if connected and otherwise $false.

By default:

Property Type Description
Connected bool Whether a connection exists and JIM answered.
Url string The JIM instance's address.
AuthMethod string How the connection authenticated: ApiKey or OAuth.
ServerVersion string The JIM version the instance reported.
Status string JIM's health status.
Message string A sentence describing the result.
TokenExpiresAt datetime When the access token expires; OAuth only.

With -Quiet: a bool.

Examples

Check connection status
Test-JIMConnection
Use in a script conditional
if (Test-JIMConnection -Quiet) {
    Write-Host "Connected to JIM"
} else {
    Connect-JIM -Url "https://jim.example.com"
}
Inspect token expiry
$status = Test-JIMConnection
if ($status.TokenExpiresAt -and $status.TokenExpiresAt -lt (Get-Date).AddMinutes(5)) {
    Write-Warning "Token expires soon; consider re-authenticating."
}

Notes

  • Checks the JIM server health endpoint to confirm reachability.
  • For OAuth sessions, reports token expiry status so you can detect sessions that are about to expire.
  • Use -Quiet in scripts where you only need a pass/fail check without the full status object.
  • If no connection has been established, the default output shows Connected = $false with an explanatory message.

See also