Sha256: 6909bcdcd686a5667b1eed20d790dda9bc77966ac9fd7cfc4daa0aa97c27cd25
Contents?: true
Size: 886 Bytes
Versions: 11
Compression:
Stored size: 886 Bytes
Contents
# frozen_string_literal: true module ShopifyApp class JWTMiddleware TOKEN_REGEX = /^Bearer\s+(.*?)$/ def initialize(app) @app = app end def call(env) return call_next(env) unless authorization_header(env) token = extract_token(env) return call_next(env) unless token set_env_variables(token, env) call_next(env) end private def call_next(env) @app.call(env) end def authorization_header(env) env['HTTP_AUTHORIZATION'] end def extract_token(env) match = authorization_header(env).match(TOKEN_REGEX) match && match[1] end def set_env_variables(token, env) jwt = ShopifyApp::JWT.new(token) env['jwt.shopify_domain'] = jwt.shopify_domain env['jwt.shopify_user_id'] = jwt.shopify_user_id env['jwt.expire_at'] = jwt.expire_at end end end
Version data entries
11 entries across 11 versions & 2 rubygems