Class: Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/authentication.rb

Overview

Authentication model conatining token generation attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grant_type: nil, username: nil, password: nil, token: nil, refresh_token: nil) ⇒ Authentication

Inialise the authentication model

Parameters:

  • grant_type (String) (defaults to: nil)

    Token grant type

  • username (String) (defaults to: nil)
  • password (String) (defaults to: nil)
  • token (String) (defaults to: nil)

    Bearer token

  • refresh_token (String) (defaults to: nil)

    Refresh token



22
23
24
25
26
27
28
# File 'lib/domain/authentication.rb', line 22

def initialize(grant_type: nil, username: nil, password: nil, token: nil, refresh_token: nil)
  self.grant_type = grant_type
  self.username = username
  self.password = password
  self.token = token
  self.refresh_token = refresh_token
end

Instance Attribute Details

#grant_typeObject

Returns the value of attribute grant_type.



7
8
9
# File 'lib/domain/authentication.rb', line 7

def grant_type
  @grant_type
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/domain/authentication.rb', line 9

def password
  @password
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



11
12
13
# File 'lib/domain/authentication.rb', line 11

def refresh_token
  @refresh_token
end

#tokenObject

Returns the value of attribute token.



10
11
12
# File 'lib/domain/authentication.rb', line 10

def token
  @token
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/domain/authentication.rb', line 8

def username
  @username
end

Class Method Details

.get_payload(auth_data) ⇒ Json

Gets Json represenatation of authentication object

Parameters:

  • auth_data (Object)

    Authentication object

Returns:

  • (Json)

    Json represenatation of authentication object



57
58
59
# File 'lib/domain/authentication.rb', line 57

def self.get_payload(auth_data)
  auth_data.as_json.to_json
end

.get_payload_with_client_info(auth_data) ⇒ Json

Gets Json represenatation of authentication object with client details

Parameters:

  • auth_data (Object)

    Authentication object

Returns:

  • (Json)

    Json represenatation of authentication object



68
69
70
# File 'lib/domain/authentication.rb', line 68

def self.get_payload_with_client_info(auth_data)
  auth_data.as_json.merge!({ 'client_id' => ApplicationConfig.client_id, 'client_secret' => ApplicationConfig.client_secret }).to_json
end

Instance Method Details

#as_json(options = {}) ⇒ Hash

Converts Authentication object to Hash and deletes null value fields

Parameters:

  • options (Refrence) (defaults to: {})

Returns:

  • (Hash)

    Hash of authentication object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/domain/authentication.rb', line 37

def as_json(options = {})
  hash_data = {
    grant_type: @grant_type,
    username: @username,
    password: @password,
    token: @token,
    refresh_token: @refresh_token
  }

  hash_data.delete_if { |k, v| v.nil? || v.empty? }
  hash_data
end