Module: AgentHarness::Authentication
- Defined in:
- lib/agent_harness/authentication.rb
Overview
Authentication management for CLI agent providers
Provides methods for checking auth status, generating OAuth URLs, and refreshing credentials for providers that support it.
Class Method Summary collapse
-
.auth_status(provider_name) ⇒ Hash
Get detailed authentication status for a provider.
-
.auth_url(provider_name) ⇒ String
Generate an OAuth URL for a provider.
-
.auth_valid?(provider_name) ⇒ Boolean
Check if authentication is valid for a provider.
-
.refresh_auth(provider_name, token: nil) ⇒ Hash
Refresh authentication credentials for a provider.
Class Method Details
.auth_status(provider_name) ⇒ Hash
Get detailed authentication status for a provider
28 29 30 31 32 33 34 35 36 |
# File 'lib/agent_harness/authentication.rb', line 28 def auth_status(provider_name) provider_name = provider_name.to_sym case provider_name when :claude, :anthropic claude_auth_status else generic_auth_status(provider_name) end end |
.auth_url(provider_name) ⇒ String
Generate an OAuth URL for a provider
Only supported for :oauth auth type providers.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/agent_harness/authentication.rb', line 45 def auth_url(provider_name) provider_name = provider_name.to_sym provider = resolve_provider(provider_name) unless provider.auth_type == :oauth raise NotImplementedError, "Provider #{provider_name} uses #{provider.auth_type} auth and does not support OAuth URL generation" end case provider_name when :claude, :anthropic claude_auth_url else raise NotImplementedError, "OAuth URL generation is not yet implemented for provider #{provider_name}" end end |
.auth_valid?(provider_name) ⇒ Boolean
Check if authentication is valid for a provider
19 20 21 22 |
# File 'lib/agent_harness/authentication.rb', line 19 def auth_valid?(provider_name) status = auth_status(provider_name) !!status[:valid] end |
.refresh_auth(provider_name, token: nil) ⇒ Hash
Refresh authentication credentials for a provider
For OAuth providers, stores a pre-exchanged token directly. This method accepts a token (not an authorization code) because the OAuth code-exchange flow is provider-specific and should be handled by the caller or a CLI login command before calling this. For API key providers, raises NotImplementedError.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/agent_harness/authentication.rb', line 75 def refresh_auth(provider_name, token: nil) provider_name = provider_name.to_sym provider = resolve_provider(provider_name) unless provider.auth_type == :oauth raise NotImplementedError, "Provider #{provider_name} uses #{provider.auth_type} auth and does not support credential refresh" end case provider_name when :claude, :anthropic refresh_claude_auth(token: token) else raise NotImplementedError, "Credential refresh is not yet implemented for provider #{provider_name}" end end |