module JwtApiAuth::Authentication

Private Instance Methods

authenticate_user() click to toggle source
# File lib/jwt_api_auth/authentication.rb, line 17
def authenticate_user
  token = request.headers['Authorization']&.split('Bearer ')&.last
  options = { algorithm: 'HS256' }

  if JwtApiAuth.token_audience.present?
    options[:aud] = JwtApiAuth.token_audience.map(&:to_s)
    options[:verify_aud] = true
  end

  ::JWT.decode token, JwtApiAuth.token_secret.call, true, options

  head :unauthorized unless token
end