Sha256: af237824cacdefa4dd0c2a6e2930de4bf7313479f07cec3ddff8aae76f8193dc
Contents?: true
Size: 887 Bytes
Versions: 28
Compression:
Stored size: 887 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
28 entries across 28 versions & 1 rubygems