asciinema.org/app/strategies/api_token_strategy.rb

23 lines
381 B
Ruby
Raw Normal View History

class ApiTokenStrategy < ::Warden::Strategies::Base
def valid?
auth.provided? && auth.basic? && auth.credentials
end
def authenticate!
user = User.for_api_token(auth.credentials.last)
user.nil? ? fail!("Invalid auth token") : success!(user)
end
def store?
false
end
private
def auth
@auth ||= Rack::Auth::Basic::Request.new(env)
end
end