Class: Anthropic::Credentials::CredentialsFile

Inherits:
ConfigProvider show all
Defined in:
lib/anthropic/credentials/credentials_file.rb

Overview

An access token provider backed by a named profile.

A profile is a pair of files under the config directory (+~/.config/anthropic/+ by default; override with ANTHROPIC_CONFIG_DIR):

  • configs/<profile>.json – non-secret. Holds the nested authentication object (discriminated by its type field), plus top-level organization_id, workspace_id, and base_url. The authentication object may contain a credentials_path field overriding the credentials file location.

  • credentials/<profile>.json – secret (0600). Holds access_token, expires_at, and (for user_oauth with a client_id) refresh_token.

Dispatches on the authentication.type discriminator:

oidc_federation

OIDC workload identity federation. Lazily constructs a WorkloadIdentity delegate from the nested auth fields plus the top-level organization_id and calls it to perform the jwt-bearer exchange.

user_oauth

Output of an interactive PKCE login. The credentials file contains the access_token (and optionally refresh_token). Currently refresh is not implemented in Ruby; the credentials file is treated as externally rotated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConfigProvider

#bind_base_url, #call, #extra_headers, #resolved_base_url

Constructor Details

#initialize(profile = nil) ⇒ CredentialsFile

Returns a new instance of CredentialsFile.

Parameters:

  • profile (String, nil) (defaults to: nil)

    profile name; if nil, resolves via ANTHROPIC_PROFILE env -> active_config pointer file -> “default”



38
39
40
41
42
43
# File 'lib/anthropic/credentials/credentials_file.rb', line 38

def initialize(profile = nil)
  super()
  @profile = profile || resolve_profile
  Anthropic::Config.validate_profile_name!(@profile)
  @config_path = config_file_path(@profile)
end

Instance Attribute Details

#config_pathPathname (readonly)

Returns path to the config file.

Returns:

  • (Pathname)

    path to the config file



34
35
36
# File 'lib/anthropic/credentials/credentials_file.rb', line 34

def config_path
  @config_path
end

#profileString (readonly)

Returns the profile name.

Returns:

  • (String)

    the profile name



31
32
33
# File 'lib/anthropic/credentials/credentials_file.rb', line 31

def profile
  @profile
end