Class: EasyJwtAuth::UserFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_jwt_auth/user_finder.rb

Instance Method Summary collapse

Constructor Details

#initializeUserFinder

Returns a new instance of UserFinder.



3
4
5
6
7
# File 'lib/easy_jwt_auth/user_finder.rb', line 3

def initialize
  @algo = Config.algo
  @finder_method = Config.finder_method
  @secret = Config.secret
end

Instance Method Details

#user_from_header(auth_header) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
# File 'lib/easy_jwt_auth/user_finder.rb', line 9

def user_from_header(auth_header)
  raise InvalidAuthHeader unless valid_header?(auth_header)

  decoded_token = JWT.decode(
    token_from_header(auth_header), secret, true, { algorithm: algo }
  )

  data = decoded_token.first
  finder_method.call(data['id'])
end