Class: ShopifyClient::Cookieless::Middleware
- Inherits:
-
Object
- Object
- ShopifyClient::Cookieless::Middleware
- Defined in:
- lib/shopify-client/cookieless/middleware.rb
Overview
Rack middleware implementing cookieless authentication with App Bridge session tokens.
Returns a 401 response if a request is unauthorised.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, is_authenticated: ->(env) { true }) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, is_authenticated: ->(env) { true }) ⇒ Middleware
Returns a new instance of Middleware.
15 16 17 18 19 |
# File 'lib/shopify-client/cookieless/middleware.rb', line 15 def initialize(app, is_authenticated: ->(env) { true }) @app = app @is_authenticated = is_authenticated end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/shopify-client/cookieless/middleware.rb', line 24 def call(env) CheckHeader.new.(env) if @is_authenticated.(env) @app.call(env) rescue UnauthorisedError Rack::Response.new do |response| response.status = 401 response.set_header('Content-Type', 'application/json') response.write({ error: 'Invalid session token', }.to_json) end.to_a end |