Class: ActionMCP::GatewayIdentifier
- Inherits:
-
Object
- Object
- ActionMCP::GatewayIdentifier
- Defined in:
- lib/action_mcp/gateway_identifier.rb
Overview
Base class for Gateway authentication identifiers.
Gateway identifiers provide a clean interface for authentication by reading from request.env keys set by upstream middleware (like Warden, Devise, or custom auth).
Direct Known Subclasses
ActionMCP::GatewayIdentifiers::ApiKeyIdentifier, ActionMCP::GatewayIdentifiers::DeviseIdentifier, ActionMCP::GatewayIdentifiers::RequestEnvIdentifier, ActionMCP::GatewayIdentifiers::WardenIdentifier
Defined Under Namespace
Classes: Unauthorized
Class Attribute Summary collapse
-
.auth_method ⇒ String
readonly
The authentication method this identifier handles (e.g., “session”, “api_key”).
-
.identifier_name ⇒ Symbol
readonly
The name of the identity this identifier provides (e.g., :user, :admin).
Class Method Summary collapse
-
.authenticates(method) ⇒ Object
Declares what authentication method this identifier handles.
-
.identifier(name) ⇒ Object
Declares what identity attribute this identifier provides.
Instance Method Summary collapse
-
#initialize(request) ⇒ GatewayIdentifier
constructor
A new instance of GatewayIdentifier.
-
#resolve ⇒ Object
abstract
Resolves the identity for this authentication method.
Constructor Details
#initialize(request) ⇒ GatewayIdentifier
Returns a new instance of GatewayIdentifier.
124 125 126 |
# File 'lib/action_mcp/gateway_identifier.rb', line 124 def initialize(request) @request = request end |
Class Attribute Details
.auth_method ⇒ String (readonly)
Returns The authentication method this identifier handles (e.g., “session”, “api_key”).
98 99 100 |
# File 'lib/action_mcp/gateway_identifier.rb', line 98 def auth_method @auth_method end |
.identifier_name ⇒ Symbol (readonly)
Returns The name of the identity this identifier provides (e.g., :user, :admin).
95 96 97 |
# File 'lib/action_mcp/gateway_identifier.rb', line 95 def identifier_name @identifier_name end |
Class Method Details
.authenticates(method) ⇒ Object
Declares what authentication method this identifier handles. This should match values in your authentication_methods configuration.
118 119 120 |
# File 'lib/action_mcp/gateway_identifier.rb', line 118 def authenticates(method) @auth_method = method.to_s end |
.identifier(name) ⇒ Object
Declares what identity attribute this identifier provides. This becomes the accessor name on the Gateway instance.
107 108 109 |
# File 'lib/action_mcp/gateway_identifier.rb', line 107 def identifier(name) @identifier_name = name.to_sym end |
Instance Method Details
#resolve ⇒ Object
Subclasses must implement this method
Resolves the identity for this authentication method. Must return a truthy identity object, or raise Unauthorized.
Common request.env keys set by popular auth middleware:
-
‘warden.user’ - Warden (used by Devise)
-
‘devise.user’ - Devise direct
-
‘rack.session’ - Rack session hash
-
‘HTTP_AUTHORIZATION’ - Authorization header
-
Custom keys set by your middleware
141 142 143 |
# File 'lib/action_mcp/gateway_identifier.rb', line 141 def resolve raise NotImplementedError, "#{self.class}#resolve must be implemented" end |