Module: AuthPassportCheckpoint::IntermediaryApi::CurrentUserHelper::ForIntermediaryApi

Included in:
Helper
Defined in:
lib/auth_passport_checkpoint/intermediary_api/current_user_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_userObject



16
17
18
19
20
21
# File 'lib/auth_passport_checkpoint/intermediary_api/current_user_helper.rb', line 16

def current_user
  return @current_user if @current_user 

  result = user_signed_request_result(AuthPassportCheckpoint.current_user_url)
  @current_user ||= (result.try(:[],:error) || result.try(:[],"error")) ? nil : result
end

#login_requiredObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/auth_passport_checkpoint/intermediary_api/current_user_helper.rb', line 5

def      
  if !current_user
    error = { 'error' => '401 Unauthorized', 'status' => 401 }
    if Object.const_defined?("Grape") and self.class == Grape::Endpoint
      error!('401 Unauthorized', 401)
    else
      render :json => error.to_json
    end
  end
end