Class: Core::Services::Applications

Inherits:
Base
  • Object
show all
Includes:
Singleton
Defined in:
lib/core/services/applications.rb

Overview

Service managing applications, allowing easy access to them with or without providing client secret for example.

Author:

Instance Method Summary collapse

Methods inherited from Base

#bad_request_err, #forbidden_err, #require_parameters, #unknown_err

Instance Method Details

#get_by_credentials(client_id: nil, client_secret: nil, **_ignored) ⇒ Core::Models::OAuth::Application

Gets an application given its credentials (client UUID and client secret).

Parameters:

  • client_id (String) (defaults to: nil)

    the unique public identifier of the application.

  • client_secret (String) (defaults to: nil)

    the password for the application.

Returns:

Raises:



20
21
22
23
24
25
26
# File 'lib/core/services/applications.rb', line 20

def get_by_credentials(client_id: nil, client_secret: nil, **_ignored)
  require_parameters client_secret: client_secret
  application = get_by_id(client_id: client_id)
  raise forbidden_err(field: 'client_secret', error: 'wrong') unless application.has_secret?(client_secret)

  application
end

#get_by_id(client_id: nil, **_ignored) ⇒ Core::Models::OAuth::Application

Gets an application given its client UUID.

Parameters:

  • client_id (String) (defaults to: nil)

    the unique identifier of the application to get

Returns:

Raises:

  • (Core::Helpers::Errors::Unknown)

    if the application is not found.



34
35
36
37
38
39
40
# File 'lib/core/services/applications.rb', line 34

def get_by_id(client_id: nil, **_ignored)
  require_parameters client_id: client_id
  application = Core::Models::OAuth::Application.find_by(client_id: client_id)
  raise unknown_err(field: 'client_id') if application.nil?

  Core::Decorators::Application.new(application)
end