Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.
This repository was archived by the owner on Mar 22, 2021. It is now read-only.

Is there any way to use Knock with route constraints? #223

Description

@toadkicker

I'm looking at authenticating Shrine presigned routes through constraints and if the Knock::Authenticatable could be leveraged in a route constraint.

Something like:

lib/constraints/authenticated_request.rb

module Constraints
  class AuthenticatedRequest
    include Knock::Authenticable

    def matches?(request)
      auth_header = request.headers.fetch('Authorization')
      return false unless auth_header
      authenticate_user
    end

  end
end

and in routes:

  mount ImageUploader.presign_endpoint(:cache) => '/images/presign', constraints: Constraints::AuthenticatedRequest.new

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions