Class: EVSS::AuthHeaders

Inherits:
BaseHeaders show all
Defined in:
lib/evss/auth_headers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ AuthHeaders

Returns a new instance of AuthHeaders.



10
11
12
13
# File 'lib/evss/auth_headers.rb', line 10

def initialize(user)
  @transaction_id = create_transaction_id
  super(user)
end

Instance Attribute Details

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



8
9
10
# File 'lib/evss/auth_headers.rb', line 8

def transaction_id
  @transaction_id
end

Instance Method Details

#create_transaction_idObject (private)



39
40
41
# File 'lib/evss/auth_headers.rb', line 39

def create_transaction_id
  "vagov-#{SecureRandom.uuid}"
end

#dependent?Boolean (private)

Returns:

  • (Boolean)


94
95
96
# File 'lib/evss/auth_headers.rb', line 94

def dependent?
  @user.person_types&.include?('DEP')
end

#eauth_jsonObject (private)



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/evss/auth_headers.rb', line 49

def eauth_json
  {
    authorizationResponse: {
      status: get_status,
      idType: 'SSN',
      id: @user.ssn,
      edi: @user.edipi,
      firstName: @user.first_name,
      lastName: @user.last_name,
      birthDate: Formatters::DateFormatter.format_date(@user.birth_date, :datetime_iso8601)
    }.merge(dependent? ? get_dependent_headers : {})
  }.to_json
end

#get_dependent_headersObject (private)



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/evss/auth_headers.rb', line 63

def get_dependent_headers
  sponsor = get_user_relationship
  return {} unless sponsor

  {
    headOfFamily: {
      id: sponsor.ssn,
      idType: 'SSN',
      edi: sponsor.edipi,
      firstName: sponsor.given_names&.first,
      lastName: sponsor.family_name,
      birthDate: Formatters::DateFormatter.format_date(sponsor.birth_date, :datetime_iso8601),
      status: 'SPONSOR'
    }
  }
end

#get_statusObject (private)



90
91
92
# File 'lib/evss/auth_headers.rb', line 90

def get_status
  dependent? ? 'DEPENDENT' : 'VETERAN'
end

#get_user_relationshipObject (private)



80
81
82
83
84
85
86
87
88
# File 'lib/evss/auth_headers.rb', line 80

def get_user_relationship
  veteran_relationships = @user.relationships&.select(&:veteran_status)
  return unless veteran_relationships.presence

  # Makes sense to give the user the ability to select the relationship eventually, for now we return
  # the first applicable relationship
  selected_relationship = veteran_relationships.first
  selected_relationship.get_full_attributes.profile
end

#sanitize(headers) ⇒ Object (private)



43
44
45
46
47
# File 'lib/evss/auth_headers.rb', line 43

def sanitize(headers)
  headers.transform_values! do |value|
    value.nil? ? '' : value
  end
end

#to_hObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/evss/auth_headers.rb', line 15

def to_h
  @headers ||= sanitize(
    'va_eauth_csid' => 'DSLogon',
    # TODO: Change va_eauth_authenticationmethod to vets.gov
    # once the EVSS team is ready for us to use it
    'va_eauth_authenticationmethod' => 'DSLogon',
    'va_eauth_pnidtype' => 'SSN',
    'va_eauth_assurancelevel' => @user.loa[:current].to_s,
    'va_eauth_firstName' => @user.first_name,
    'va_eauth_lastName' => @user.last_name,
    'va_eauth_issueinstant' => @user.last_signed_in&.iso8601,
    'va_eauth_dodedipnid' => @user.edipi,
    'va_eauth_birlsfilenumber' => @user.birls_id,
    'va_eauth_pid' => @user.participant_id,
    'va_eauth_pnid' => @user.ssn,
    'va_eauth_birthdate' => Formatters::DateFormatter.format_date(@user.birth_date, :datetime_iso8601),
    'va_eauth_authorization' => eauth_json,
    'va_eauth_authenticationauthority' => 'eauth',
    'va_eauth_service_transaction_id' => @transaction_id
  )
end