Class: AuthenticationService

Inherits:
Object
  • Object
show all
Defined in:
lib/services/authentication_service.rb

Overview

Authentication Service for token activies

Class Method Summary collapse

Class Method Details

.create_authentication(auth_data) ⇒ Json

Creates authentication token

Parameters:

  • auth_data (object)

    Authentication object

Returns:

  • (Json)

    Response with brearer and refresh token



17
18
19
20
21
22
23
24
# File 'lib/services/authentication_service.rb', line 17

def self.create_authentication(auth_data)
  auth_data = get_auth_with_client_info(auth_data)
  auth_payload = Authentication.get_payload(auth_data)
  RestClient::Request.execute(method: :post,
                              url: ApplicationConfig.get_url('create_authentication_path'),
                              payload: auth_payload,
                              headers: { 'Content-Type': 'application/json' })
end

.get_auth_with_client_info(auth_data) ⇒ Object

Sets Client id and secrets to Authentication object

Parameters:

  • auth_data (Object)

    Authentication object

Returns:

  • (Object)

    Authentication object



68
69
70
71
72
# File 'lib/services/authentication_service.rb', line 68

def self.get_auth_with_client_info(auth_data)
  auth_data.client_id = ApplicationConfig.client_id
  auth_data.client_secret = ApplicationConfig.client_secret
  auth_data
end

.refresh_authentication_token(auth_data, bearer_token) ⇒ Json

Refresh authentication token

Parameters:

  • auth_data (Object)

    Authentication object

  • bearer_token (String)

Returns:

  • (Json)

    Response with brearer and refresh token



34
35
36
37
38
39
40
41
42
# File 'lib/services/authentication_service.rb', line 34

def self.refresh_authentication_token(auth_data, bearer_token)
  auth_data = get_auth_with_client_info(auth_data)
  auth_payload = Authentication.get_payload(auth_data)
  RestClient::Request.execute(method: :post,
                              url: ApplicationConfig.get_url('create_authentication_path'),
                              payload: auth_payload,
                              headers: { 'Content-Type': 'application/json',
                                         'Authorization': bearer_token })
end

.revoke_authentication_token(auth_data, bearer_token) ⇒ Json

Revokes authentication token

Parameters:

  • auth_data (Object)

    Authentication object

  • bearer_token (String)

Returns:

  • (Json)

    Response with revoke message



52
53
54
55
56
57
58
59
# File 'lib/services/authentication_service.rb', line 52

def self.revoke_authentication_token(auth_data, bearer_token)
  auth_payload = Authentication.get_payload(auth_data)
  RestClient::Request.execute(method: :post,
                              url: ApplicationConfig.get_url('revoke_authentication_path'),
                              payload: auth_payload,
                              headers: { 'Content-Type': 'application/json',
                                         'Authorization': bearer_token })
end