Module: Doorkeeper::Grape::Helpers

Extended by:
Grape::API::Helpers
Includes:
Rails::Helpers
Defined in:
lib/doorkeeper/grape/helpers.rb

Overview

Doorkeeper helpers for Grape applications. Provides helpers for endpoints authorization based on defined set of scopes.

Instance Method Summary collapse

Methods included from Rails::Helpers

#doorkeeper_forbidden_render_options, #doorkeeper_unauthorized_render_options, #valid_doorkeeper_token?

Instance Method Details

#doorkeeper_authorize!(*scopes) ⇒ Object

endpoint specific scopes > parameter scopes > default scopes


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/doorkeeper/grape/helpers.rb', line 15

def doorkeeper_authorize!(*scopes)
  endpoint_scopes = endpoint.route_setting(:scopes) ||
                    endpoint.options[:route_options][:scopes]

  scopes = if endpoint_scopes
             Doorkeeper::OAuth::Scopes.from_array(endpoint_scopes)
           elsif scopes.present?
             Doorkeeper::OAuth::Scopes.from_array(scopes)
           end

  super(*scopes)
end

#doorkeeper_render_error_with(error) ⇒ Object


28
29
30
31
# File 'lib/doorkeeper/grape/helpers.rb', line 28

def doorkeeper_render_error_with(error)
  status_code = error_status_codes[error.status]
  error!({ error: error.description }, status_code, error.headers)
end