Module: PadlockAuth::Rails::ActionCableChannelHelpers

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

Defined Under Namespace

Modules: TokenFactory

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



66
67
68
# File 'lib/padlock_auth/rails/action_cable_channel_helpers.rb', line 66

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

#padlock_authorized?(*scopes) ⇒ Boolean

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.

Returns:

  • (Boolean)

    Whether the request is authorized.



54
55
56
# File 'lib/padlock_auth/rails/action_cable_channel_helpers.rb', line 54

def padlock_authorized?(*scopes)
  padlock_auth_token&.acceptable?(scopes.presence || PadlockAuth.config.default_scopes)
end