You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.
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
The text was updated successfully, but these errors were encountered:
I know this is an old issue but I bumped into this problem today. This is the current implementation I'm using:
##
# This constraint asserts the current user is an admin
class AdminConstraint
def matches?(request)
return false unless request.headers['Authorization']
token = request.headers['Authorization'].split(' ')[1]
user_id = Knock::AuthToken.new(token: token).payload['sub']
user = User.find(user_id)
user.admin?
end
end
Be wary as I'm not familiar with the Knock APIs.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
and in routes:
The text was updated successfully, but these errors were encountered: