Class: ShopifyClient::Cookieless::CheckHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify-client/cookieless/check_header.rb

Constant Summary collapse

UnauthorisedError =
Class.new(Error)

Instance Method Summary collapse

Instance Method Details

#call(rack_env) ⇒ Object

Parameters:

  • rack_env (Hash)

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shopify-client/cookieless/check_header.rb', line 13

def call(rack_env)
  header = rack_env['HTTP_AUTHORIZATION']

  raise UnauthorisedError, 'missing Authorization header' if header.nil?

  session_token = header.[](/Bearer (\S+)/, 1)

  raise UnauthorisedError, 'invalid Authorization header' if session_token.nil?

  rack_env['shopify-client.shop'] = DecodeSessionToken.new.(session_token)
rescue DecodeSessionToken::Error
  raise UnauthorisedError, 'invalid session token'
end