Class: Lockie::Strategies::Jwt

Inherits:
Warden::Strategies::Base
  • Object
show all
Includes:
LogHelper, ModelHelper
Defined in:
lib/lockie/strategies/jwt.rb

Instance Method Summary collapse

Methods included from LogHelper

#set_message

Methods included from ModelHelper

#auth_object

Instance Method Details

#authObject



7
8
9
# File 'lib/lockie/strategies/jwt.rb', line 7

def auth
  @auth ||= ActionDispatch::Request.new(env)
end

#authenticate!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lockie/strategies/jwt.rb', line 23

def authenticate!
  begin
    auth = auth_object.find_by_token(token)
    if auth
      success! auth
    else
      set_message "Invalid token"
      fail!
    end
  rescue # => err
    set_message "Invalid token"
    fail!
  end
end

#headersObject



11
12
13
# File 'lib/lockie/strategies/jwt.rb', line 11

def headers
  auth.headers
end

#tokenObject



19
20
21
# File 'lib/lockie/strategies/jwt.rb', line 19

def token
  headers['Authorization'].split.last.strip
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/lockie/strategies/jwt.rb', line 15

def valid?
  headers['Authorization'].present?
end