module Rails::Vault::JWT::Concerns::AuthRequired
Protected Instance Methods
authenticate_request!()
click to toggle source
# File lib/rails/vault/jwt/concerns/auth_required.rb, line 18 def authenticate_request! unless token_valid? render json: { errors: ['Not Authenticated'] }, status: :unauthorized nil end rescue ::JWT::VerificationError, ::JWT::DecodeError => e JWT.config.logger.debug { "Error while verifying token: #{e}" } render json: { errors: ['Not Authenticated'] }, status: :unauthorized end
Private Instance Methods
auth_token()
click to toggle source
# File lib/rails/vault/jwt/concerns/auth_required.rb, line 37 def auth_token @auth_token ||= JWT::Decoder.decode(http_token) JWT.config.logger.debug { "@auth_token => #{@auth_token}" } @auth_token end
http_token()
click to toggle source
# File lib/rails/vault/jwt/concerns/auth_required.rb, line 30 def http_token @http_token ||= (request.headers['Authorization'].split.last if request.headers['Authorization'].present?) JWT.config.logger.debug { "@http_token => #{@http_token}" } @http_token end
token_expired?()
click to toggle source
# File lib/rails/vault/jwt/concerns/auth_required.rb, line 48 def token_expired? exp = auth_token[:exp].to_i DateTime.now.to_time.to_i > exp end
token_valid?()
click to toggle source
# File lib/rails/vault/jwt/concerns/auth_required.rb, line 44 def token_valid? http_token && auth_token && !token_expired? end