Class: Core::Services::Authorizations
- Includes:
- Singleton
- Defined in:
- lib/core/services/authorizations.rb
Overview
Service managing authorization codes. These codes represent the access a user is giving to an application on all or part of its data.
Instance Method Summary collapse
-
#create_from_session(session_id: nil, client_id: nil, **ignored) ⇒ Code::Decorators::Authorization
Creates an authorization to access to the data of the user for the application.
-
#get_by_code(authorization_code: nil, **_ignored) ⇒ Core::Models::OAuth::Authorization
Gets an authorization code by its corresponding value.
-
#get_by_credentials(client_id: nil, client_secret: nil, authorization_code: nil, **_ignored) ⇒ Core::Models::OAuth::Authorization
Gets the authorization code corresponding to the provided value if it is linked to the application matching the provided credentials.
Methods inherited from Base
#bad_request_err, #forbidden_err, #require_parameters, #unknown_err
Instance Method Details
#create_from_session(session_id: nil, client_id: nil, **ignored) ⇒ Code::Decorators::Authorization
Creates an authorization to access to the data of the user for the application. The user is identified by the UUID of its current connection session.
- WARNING
-
this method should NOT be used outside of the authentication backend.
21 22 23 24 25 26 27 28 29 |
# File 'lib/core/services/authorizations.rb', line 21 def create_from_session(session_id: nil, client_id: nil, **ignored) session = Core.svc.sessions.get_by_id(session_id: session_id) application = Core.svc.applications.get_by_id(client_id: client_id) = Core::Models::OAuth::Authorization.create( account: session.account, application: application ) Core::Decorators::Authorization.new() end |
#get_by_code(authorization_code: nil, **_ignored) ⇒ Core::Models::OAuth::Authorization
Gets an authorization code by its corresponding value.
60 61 62 63 64 65 66 |
# File 'lib/core/services/authorizations.rb', line 60 def get_by_code(authorization_code: nil, **_ignored) require_parameters authorization_code: = Core::Models::OAuth::Authorization.find_by(code: ) raise unknown_err(field: 'authorization_code') if .nil? Core::Decorators::Authorization.new() end |
#get_by_credentials(client_id: nil, client_secret: nil, authorization_code: nil, **_ignored) ⇒ Core::Models::OAuth::Authorization
Gets the authorization code corresponding to the provided value if it is linked to the application matching the provided credentials. Otherwise it raises errors.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/core/services/authorizations.rb', line 44 def get_by_credentials(client_id: nil, client_secret: nil, authorization_code: nil, **_ignored) require_parameters authorization_code: application = Core.svc.applications.get_by_credentials( client_id: client_id, client_secret: client_secret ) = get_by_code(authorization_code: ) raise mismatch_error if .application.id.to_s != application.id.to_s end |