Class: ClaudeAgentServer::Middleware::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_agent_server/middleware/authentication.rb

Constant Summary collapse

SKIP_PATHS =
%w[/health /v1/health].freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Authentication

Returns a new instance of Authentication.



11
12
13
# File 'lib/claude_agent_server/middleware/authentication.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/claude_agent_server/middleware/authentication.rb', line 15

def call(env)
  return @app.call(env) unless ClaudeAgentServer.config.auth_enabled?
  return @app.call(env) if skip_auth?(env)

  token = extract_token(env)
  return unauthorized_response unless token && timing_safe_compare(token, ClaudeAgentServer.config.auth_token)

  @app.call(env)
end