Class: Clerk::AuthenticateRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/clerk/authenticate_request.rb

Overview

This class represents a service object used to determine the current request state for the current env passed based on a provided Clerk::AuthenticateContext. There is only 1 public method exposed (‘resolve`) to be invoked with a env parameter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_context) ⇒ AuthenticateRequest

Creates a new instance using Clerk::AuthenticateContext object.



14
15
16
# File 'lib/clerk/authenticate_request.rb', line 14

def initialize(auth_context)
  @auth_context = auth_context
end

Instance Attribute Details

#auth_contextObject (readonly)

Returns the value of attribute auth_context.



11
12
13
# File 'lib/clerk/authenticate_request.rb', line 11

def auth_context
  @auth_context
end

Instance Method Details

#resolve(env) ⇒ Object

Determines the current request state by verifying a Clerk token in headers or cookies. The possible outcomes of this method are ‘signed-in`, `signed-out` or `handshake` states. The return values are the same as a return value of a rack middleware `[http_status_code, headers, body]`. When used in a middleware the consumer of this service should return the return value when there is an `http_status_code` provided otherwise the should continue with the middleware chain. The headers provided in the return value is a hash of { header_key => header_value } and in the case of a `Set-Cookie` header the `header_value` used is a list of raw HTTP Set-Cookie directives.



25
26
27
28
29
30
31
# File 'lib/clerk/authenticate_request.rb', line 25

def resolve(env)
  if auth_context.session_token_in_header?
    resolve_header_token(env)
  else
    resolve_cookie_token(env)
  end
end