Sha256: bbcf985d583763a73218d46182c8795d38bb249799e48847918241cfaa674091
Contents?: true
Size: 691 Bytes
Versions: 7
Compression:
Stored size: 691 Bytes
Contents
module Commons module Authentication module AuthenticateByJWT def authorize_jwt! raise Commons::Errors::Unauthorized if jwt.blank? begin decoded = JSONWebToken.decode(jwt) @current_user = UserRepository.instance.find_by(id: decoded[:user_id]) rescue ActiveRecord::RecordNotFound => e raise Commons::Errors::Unauthorized rescue JWT::DecodeError => e raise Commons::Errors::Unauthorized end end private def jwt jwt ||= request.headers['Authorization'] return nil unless jwt.instance_of? String jwt = jwt.split(' ').last if jwt end end end end
Version data entries
7 entries across 7 versions & 1 rubygems