Module: JWT::Auth::Authentication

Defined in:
lib/jwt/auth/authentication.rb

Overview

Controller methods

Instance Method Summary collapse

Instance Method Details

#authenticate_userObject

Authenticate a request



21
22
23
# File 'lib/jwt/auth/authentication.rb', line 21

def authenticate_user
  raise JWT::Auth::UnauthorizedError unless jwt && jwt.valid?
end

#current_userObject

Current user helper



14
15
16
# File 'lib/jwt/auth/authentication.rb', line 14

def current_user
  jwt && jwt.subject
end

#renew_tokenObject

Add JWT header to response



28
29
30
31
32
# File 'lib/jwt/auth/authentication.rb', line 28

def renew_token
  return unless jwt && jwt.valid?
  jwt.renew!
  response.headers['Authorization'] = "Bearer #{jwt.to_jwt}"
end