Sha256: 1a648ded88d005fcd996c037c5c6f7ffe714d86c2d5c915a51de11f7ac7f6ad4
Contents?: true
Size: 1 KB
Versions: 11
Compression:
Stored size: 1 KB
Contents
module ApiUserAuth # Base controller module module Controller extend ActiveSupport::Concern included do before_action :authenticate rescue_from Exceptions::Unauthorized, with: :auth_user_unauthorized end def auth_user_unauthorized(exception) render json: { message: exception.message }, status: 401 end private def authenticate if request.headers['Authorization'].blank? raise Exceptions::Unauthorized, 'Header [Authorization] can not be blank!' end http_authenticate if @auth_user.blank? raise Exceptions::Unauthorized, 'Header [Authorization] token is invalid!' end end def http_authenticate authenticate_with_http_token do |token, _options| unless token =~ ApiUserAuth::UUID_REGEX raise Exceptions::Unauthorized, 'Header [Authorization] token is invalid!' end @auth_user = AuthUser.find_fy_token(token) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems