Skip to content

Add accessTokenFromEnv authentication method #169

@kop

Description

@kop

Summary

Add a new authentication option accessTokenFromEnv that reads an access token from a specified environment variable at connection time.

Motivation

This would help in two scenarios:

  1. Local development and quick prototyping — developers can export a short-lived token in their shell and immediately run scripts without wiring up a full service account flow.
  2. Security-constrained environments — in setups where credentials (client ID/secret) cannot be stored on local machines, an externally-provisioned token injected via environment variable is the only viable auth path.

Proposed behavior

accessTokenFromEnv accepts a string — the name of the environment variable that holds the access token.

const connection = await firebolt.connect({
  auth: {
    accessTokenFromEnv: "FIREBOLT_TOKEN",
  },
  engineName: 'engine_name',
  account: 'account_name',
  database: 'database',
});

At connection time, the SDK reads process.env.FIREBOLT_TOKEN. If the variable is set and non-empty, its value is used as the access token (equivalent to passing accessToken directly).

Combining with other auth methods

Unlike other auth options, accessTokenFromEnv can be specified alongside client_id/client_secret. When both are present, accessTokenFromEnv takes priority if the environment variable is set; otherwise the SDK falls back to the client credentials flow:

const connection = await firebolt.connect({
  auth: {
    // Use process.env.FIREBOLT_TOKEN if set
    accessTokenFromEnv: "FIREBOLT_TOKEN",
    // Fall back to client credentials otherwise
    client_id: 'b1c4918c-e07e-4ab2-868b-9ae84f208d26',
    client_secret: 'secret',
  },
  engineName: 'engine_name',
  account: 'account_name',
  database: 'database',
});

Resolution order

  1. If accessTokenFromEnv is specified and process.env[value] is set and non-empty → use it as the access token.
  2. Otherwise, if client_id/client_secret are provided → use client credentials auth.
  3. Otherwise → throw an authentication error.

Type changes

type ConnectionOptions = {
  auth: AccessTokenAuth | ClientCredentialsAuth | FireboltCoreAuth | EnvTokenAuth | EnvTokenWithFallbackAuth;
  // ...
};

type EnvTokenAuth = {
  accessTokenFromEnv: string;
};

type EnvTokenWithFallbackAuth = {
  accessTokenFromEnv: string;
  client_id: string;
  client_secret: string;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions