Module: PadlockAuth::Rails::Helpers

Defined in:
lib/padlock_auth/rails/helpers.rb

Overview

Helpers for Rails controllers.

Provides ‘padlock_authorize!` method to controllers.

Instance Method Summary collapse

Instance Method Details

#padlock_auth_tokenPadlockAuth::AbstractToken?

Retrieve the access token from the request.

Does not check if the token is valid or matches the required scopes.

Returns:

  • (PadlockAuth::AbstractToken, nil)

    Access token



85
86
87
# File 'lib/padlock_auth/rails/helpers.rb', line 85

def padlock_auth_token
  @padlock_auth_token ||= TokenFactory.authenticate(request)
end

#padlock_authorize!Object

Authorize the request with the given scopes.

If the request is not authorized, an error response will be rendered or an exception will be raised, depending on the configuration.

Parameters:

  • scopes (Array<String>)

    Scopes required for the request, defaults to the default scopes.



19
20
21
# File 'lib/padlock_auth/rails/helpers.rb', line 19

def padlock_authorize!(...)
  padlock_render_error unless padlock_authorized?(...)
end