Module: Knock::Authenticable

Defined in:
lib/knock/authenticable.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject



13
14
15
# File 'lib/knock/authenticable.rb', line 13

def authenticate
  head :unauthorized unless current_user
end

#current_userObject



2
3
4
5
6
7
8
9
10
11
# File 'lib/knock/authenticable.rb', line 2

def current_user
  @current_user ||= begin
    token = params[:token] ||
      request.headers['Authorization'].match(/^Bearer (.*)$/)[1]

    Knock::AuthToken.new(token: token).current_user
  rescue
    nil
  end
end