Class: Anthropic::Credentials::CredentialsFile
- Inherits:
-
ConfigProvider
- Object
- ConfigProvider
- Anthropic::Credentials::CredentialsFile
- 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
authenticationobject (discriminated by itstypefield), plus top-levelorganization_id,workspace_id, andbase_url. Theauthenticationobject may contain acredentials_pathfield overriding the credentials file location. -
credentials/<profile>.json – secret (0600). Holds
access_token,expires_at, and (foruser_oauthwith aclient_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_idand calls it to perform the jwt-bearer exchange. user_oauth-
Output of an interactive PKCE login. The credentials file contains the
access_token(and optionallyrefresh_token). Currently refresh is not implemented in Ruby; the credentials file is treated as externally rotated.
Instance Attribute Summary collapse
-
#config_path ⇒ Pathname
readonly
Path to the config file.
-
#profile ⇒ String
readonly
The profile name.
Instance Method Summary collapse
-
#initialize(profile = nil) ⇒ CredentialsFile
constructor
A new instance of CredentialsFile.
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.
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_path ⇒ Pathname (readonly)
Returns path to the config file.
34 35 36 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 34 def config_path @config_path end |
#profile ⇒ String (readonly)
Returns the profile name.
31 32 33 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 31 def profile @profile end |