class Rack::BearerAuth::MatchPattern

Attributes

path[R]
token[R]
via[R]

Public Class Methods

new(path, via, token) click to toggle source
# File lib/rack/bearer_auth/match_pattern.rb, line 8
def initialize(path, via, token)
  raise ArgumentError, "Token pattern is required" unless token

  @path = Path.new(path)
  @via = Via.new(via)
  @token = Token.new(token)
end

Public Instance Methods

match(req) click to toggle source
# File lib/rack/bearer_auth/match_pattern.rb, line 16
def match(req)
  return :skip unless match_route?(req)
  return :token_required unless req.token

  token.match?(req.token) ? :ok : :invalid_token
end

Private Instance Methods

match_route?(req) click to toggle source
# File lib/rack/bearer_auth/match_pattern.rb, line 25
def match_route?(req)
  path.match?(req.path) && via.match?(req.via)
end