Module: JWT::Auth::Authentication
- Defined in:
- lib/jwt/auth/authentication.rb
Overview
Controller methods
Instance Method Summary collapse
-
#add_token_to_response ⇒ Object
Add JWT header to response.
-
#authenticate_user ⇒ Object
Authenticate a request.
-
#current_user ⇒ Object
Current user helper.
Instance Method Details
#add_token_to_response ⇒ Object
Add JWT header to response
31 32 33 34 35 |
# File 'lib/jwt/auth/authentication.rb', line 31 def add_token_to_response return unless token&.valid? token.renew! response.headers['Authorization'] = "Bearer #{token.to_jwt}" end |
#authenticate_user ⇒ Object
Authenticate a request
21 22 23 24 25 26 |
# File 'lib/jwt/auth/authentication.rb', line 21 def authenticate_user return head :unauthorized unless token&.valid? # Regenerate token (renews expiration date) add_token_to_response end |
#current_user ⇒ Object
Current user helper
14 15 16 |
# File 'lib/jwt/auth/authentication.rb', line 14 def current_user token&.subject end |