module ApiUserAuth::Controller

Base controller module

Public Instance Methods

auth_user_unauthorized(exception) click to toggle source
# File lib/api_user_auth/controller.rb, line 11
def auth_user_unauthorized(exception)
  render json: { message: exception.message }, status: 401
end

Private Instance Methods

authenticate() click to toggle source
# File lib/api_user_auth/controller.rb, line 17
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
http_authenticate() click to toggle source
# File lib/api_user_auth/controller.rb, line 29
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