Class: Soteria::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/soteria/auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(cert, key, pw, log) ⇒ Auth

Create a Auth object to make auth calls.

Parameters:

  • cert (String)

    The relative path to the SSL cert on the server.

  • key (String)

    The relative path to the SSL cert key on the server.

  • pw (String)

    The password for the cert key file.

  • log (Boolean)

    if the client should log everything. This is good for development.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/soteria/auth.rb', line 12

def initialize(cert, key, pw, log)

  @client = Savon.client(wsdl: 'lib/wsdl/vip_auth.wsdl',
                         env_namespace: :soapenv,
                         endpoint: 'https://services-auth.vip.symantec.com/mgmt/soap',
                         log: log,
                         ssl_version: :TLSv1,
                         ssl_cert_file: cert,
                         ssl_cert_key_file: key,
                         ssl_cert_key_password: pw,
                         namespace_identifier: :vip)

  @prov_client = Savon.client(wsdl: 'lib/wsdl/vip_auth.wsdl',
                              env_namespace: :soapenv,
                              endpoint: 'https://services-auth.vip.symantec.com/prov/soap',
                              log: log,
                              ssl_version: :TLSv1,
                              ssl_cert_file: cert,
                              ssl_cert_key_file: key,
                              ssl_cert_key_password: pw,
                              namespace_identifier: :vip)

  @val_client = Savon.client(wsdl: 'lib/wsdl/vip_auth.wsdl',
                             env_namespace: :soapenv,
                             endpoint: 'https://services-auth.vip.symantec.com/val/soap',
                             log: log,
                             ssl_version: :TLSv1,
                             ssl_cert_file: cert,
                             ssl_cert_key_file: key,
                             ssl_cert_key_password: pw,
                             namespace_identifier: :vip)
end

Instance Method Details

#activate_token(token_id) ⇒ Hash

Call when a newly registered SMS OTP credential requires activation

Parameters:

  • token_id (Int)

    Specifies the phone number that identifies the credential to the VIP Web Services. Do not use spaces or dashes.

Returns:

  • (Hash)

    A hash that contains; :success a boolean if the call succeeded, :message a string with any error message, :id the id of the call for debugging purposes



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/soteria/auth.rb', line 112

def activate_token(token_id)
  res = @client.call(:activate_token,
                     message: {
                         'vip:TokenId': token_id
                     },
                     attributes: {
                         'Version': '3.1',
                         'Id': Utilities.get_request_id('activate_token')
                     }
  ).body

  get_return_hash(res[:activate_token_response])
end

#deactivate_token(token_id) ⇒ Hash

Use the DeactivateToken for SMS OTP API to deactivate an SMS OTP credential. If the deactivation is successful, the credential is deactivated.

Parameters:

  • token_id (Int)

    Specifies the phone number that identifies the credential to the VIP Web Services. Do not use spaces or dashes.

Returns:

  • (Hash)

    A hash that contains; :success a boolean if the call succeeded, :message a string with any error message, :id the id of the call for debugging purposes



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/soteria/auth.rb', line 131

def deactivate_token(token_id)
  res = @client.call(:deactivate_token,
                     message: {
                         'vip:TokenId': token_id
                     },
                     attributes: {
                         'Version': '3.1',
                         'Id': Utilities.get_request_id('deactivate_token')
                     }
  ).body

  get_return_hash(res[:deactivate_token_response])
end

#disable_sms_credentail(reason, token_id) ⇒ Hash

Use the DisableToken for SMS OTP API to disable an SMS OTP credential.

Parameters:

  • reason (String)

    The reason for disabling the token.

  • token_id (Int)

    Specifies the phone number that identifies the credential to the VIP Web Services. Do not use spaces or dashes.

Returns:

  • (Hash)

    A hash that contains; :success a boolean if the call succeeded, :message a string with any error message, :id the id of the call for debugging purposes



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/soteria/auth.rb', line 92

def disable_sms_credentail(reason, token_id)
  res = @client.call(:disable_token,
                     message: {
                         'vip:TokenId': token_id,
                         'vip:TemporaryPassword': pass
                     },
                     attributes: {
                         'Version': '3.1',
                         'Id': Utilities.get_request_id('disable_sms_credentail')
                     }
  ).body

  get_return_hash(res[:enable_token_response])
end

#enable_sms_credentail(token_id) ⇒ Hash

Use the EnableToken for SMS OTP API to enable a previously disabled SMS OTP credential.

Parameters:

  • token_id (Int)

    Specifies the phone number that identifies the credential to the VIP Web Services. Do not use spaces or dashes.

Returns:

  • (Hash)

    A hash that contains; :success a boolean if the call succeeded, :message a string with any error message, :id the id of the call for debugging purposes



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/soteria/auth.rb', line 71

def enable_sms_credentail(token_id)
  res = @client.call(:enable_token,
                     message: {
                         'vip:TokenId': token_id,
                         'vip:TemporaryPassword': pass
                     },
                     attributes: {
                         'Version': '3.1',
                         'Id': Utilities.get_request_id('enable_sms_credentail')
                     }
  ).body

  get_return_hash(res[:enable_token_response])
end

#get_return_hash(res) ⇒ Hash

Helper function to create the hash to return. All user calls have the same return values.

Parameters:

  • res (Hash)

Returns:

  • (Hash)

    A hash with the appropriate values. Included are: :success - a boolean if the operation was successful,



197
198
199
200
201
202
203
204
205
# File 'lib/soteria/auth.rb', line 197

def get_return_hash(res)
  response_hash = res[:status]

  {
      success: response_hash[:reason_code] == '0000',
      message: response_hash[:status_message],
      id: res[:@request_id]
  }
end

#register(token_id) ⇒ Hash

Register a new SMS OTP credential.

Parameters:

  • token_id (Int)

    Specifies the phone number that identifies the credential to the VIP Web Services. Do not use spaces or dashes.

Returns:

  • (Hash)

    A hash that contains; :success a boolean if the call succeeded, :message a string with any error message, :id the id of the call for debugging purposes



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/soteria/auth.rb', line 150

def register(token_id)
  res = @prov_client.call(:register,
                          message: {
                              'vip:TokenId': token_id,
                              attributes!: {
                                  'vip:TokenId':
                                      {
                                          type: 'SMS'
                                      }
                              }
                          },
                          attributes: {
                              'Version': '3.1',
                              'Id': Utilities.get_request_id('register')
                          }
  ).body

  get_return_hash(res[:enable_token_response])
end

#send_temp_pass(token_id) ⇒ Hash

If a user’s credential is lost or stolen, use the SendTemporaryPassword for SMS API to generate and send a temporary security code to the user’s phone number. The system-generated, temporary security code is sent using SMS, and is valid for one use only. The temporary security code must be used before the specified expiration time (up to seven days).

Parameters:

  • token_id (Int)

    Specifies the phone number that identifies the credential to the VIP Web Services. Do not use spaces or dashes.

Returns:

  • (Hash)

    A hash that contains; :success a boolean if the call succeeded, :message a string with any error message, :id the id of the call for debugging purposes



177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/soteria/auth.rb', line 177

def send_temp_pass(token_id)
  res = client.call(:send_temporary_password,
             message: {
                 'vip:TokenId': token_id,
                 'vip:PhoneNumber': token_id
             },
             attributes: {
                 'Version': '3.1',
                 'Id': Utilities.get_request_id('send_temp_pass')
             }
  ).body

  get_return_hash(res[:send_temporary_password_response])
end

#set_temp_pass(token_id, pass) ⇒ Hash

Send a temporary password to the token.

Parameters:

  • token_id (Int)

    Specifies the phone number that identifies the credential to the VIP Web Services. Do not use spaces or dashes.

  • pass (Int)

Returns:

  • (Hash)

    A hash that contains; :success a boolean if the call succeeded, :message a string with any error message, :id the id of the call for debugging purposes



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/soteria/auth.rb', line 51

def set_temp_pass(token_id, pass)
  res = @client.call(:set_temporary_password,
                     message: {
                         'vip:TokenId': token_id,
                         'vip:TemporaryPassword': pass
                     },
                     attributes: {
                         'Version': '3.1',
                         'Id': Utilities.get_request_id('set_temp_pass')
                     }
  ).body

  get_return_hash(res[:set_temporary_password_response])
end