Class: RailsJwtAuth::Jwt::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_jwt_auth/jwt/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
# File 'lib/rails_jwt_auth/jwt/request.rb', line 6

def initialize(request)
  return unless request.env['HTTP_AUTHORIZATION']
  @jwt = request.env['HTTP_AUTHORIZATION'].split.last
  @jwt_info = RailsJwtAuth::Jwt::Manager.decode(@jwt)
end

Instance Method Details

#auth_tokenObject



24
25
26
# File 'lib/rails_jwt_auth/jwt/request.rb', line 24

def auth_token
  payload ? payload['auth_token'] : nil
end

#headerObject



20
21
22
# File 'lib/rails_jwt_auth/jwt/request.rb', line 20

def header
  @jwt_info ? @jwt_info[1] : nil
end

#payloadObject



16
17
18
# File 'lib/rails_jwt_auth/jwt/request.rb', line 16

def payload
  @jwt_info ? @jwt_info[0] : nil
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rails_jwt_auth/jwt/request.rb', line 12

def valid?
  @jwt && RailsJwtAuth::Jwt::Manager.valid_payload?(payload)
end