Class: A2A::Plugins::ExampleAuth
- Inherits:
-
A2A::Plugin::AuthPlugin
- Object
- A2A::Plugin::Base
- A2A::Plugin::AuthPlugin
- A2A::Plugins::ExampleAuth
- Defined in:
- lib/a2a/plugins/example_auth.rb
Instance Attribute Summary
Attributes inherited from A2A::Plugin::Base
Instance Method Summary collapse
-
#authenticate_request(request, **options) ⇒ Hash
Authenticate request.
- #cleanup ⇒ Object private
- #generate_token(options) ⇒ Object private
-
#register_hooks(plugin_manager) ⇒ Object
Register hooks for this plugin.
- #setup ⇒ Object private
-
#strategy_name ⇒ Object
Authentication strategy name.
-
#validate_credentials(credentials) ⇒ Boolean
Validate credentials.
Methods inherited from A2A::Plugin::Base
dependencies, depends_on, inherited, #initialize, plugin_type
Constructor Details
This class inherits a constructor from A2A::Plugin::Base
Instance Method Details
#authenticate_request(request, **options) ⇒ Hash
Authenticate request
21 22 23 24 25 26 27 28 29 |
# File 'lib/a2a/plugins/example_auth.rb', line 21 def authenticate_request(request, **) logger&.info("Authenticating request with Example Auth") # Add custom authentication header request[:headers] ||= {} request[:headers]["X-Example-Auth"] = generate_token() request end |
#cleanup ⇒ Object (private)
65 66 67 68 |
# File 'lib/a2a/plugins/example_auth.rb', line 65 def cleanup @secret_key = nil logger&.info("Example Auth plugin cleaned up") end |
#generate_token(options) ⇒ Object (private)
70 71 72 73 74 75 76 77 78 |
# File 'lib/a2a/plugins/example_auth.rb', line 70 def generate_token() # Simple token generation - in real implementation, use proper JWT or similar payload = { timestamp: Time.now.to_i, client_id: [:client_id] || "unknown" } Base64.encode64("#{payload.to_json}:#{@secret_key}").strip end |
#register_hooks(plugin_manager) ⇒ Object
Register hooks for this plugin
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/a2a/plugins/example_auth.rb', line 43 def register_hooks(plugin_manager) plugin_manager.add_hook(A2A::Plugin::Events::BEFORE_REQUEST) do |request| logger&.debug("Example Auth: Validating request authentication") # Add request timestamp for security request[:auth_timestamp] = Time.now.to_i end plugin_manager.add_hook(A2A::Plugin::Events::REQUEST_ERROR) do |error, request| if error.is_a?(A2A::Errors::AuthenticationError) logger&.warn("Example Auth: Authentication failed for request #{request[:id]}") end end end |
#setup ⇒ Object (private)
60 61 62 63 |
# File 'lib/a2a/plugins/example_auth.rb', line 60 def setup @secret_key = config[:secret_key] || "default_secret" logger&.info("Example Auth plugin initialized") end |
#strategy_name ⇒ Object
Authentication strategy name
13 14 15 |
# File 'lib/a2a/plugins/example_auth.rb', line 13 def strategy_name "example" end |
#validate_credentials(credentials) ⇒ Boolean
Validate credentials
34 35 36 37 38 39 40 |
# File 'lib/a2a/plugins/example_auth.rb', line 34 def validate_credentials(credentials) return false unless credentials.is_a?(Hash) return false unless credentials[:api_key] # Simple validation - in real implementation, validate against backend credentials[:api_key].start_with?("example_") end |