Class: Soteria::Credential
- Inherits:
-
Object
- Object
- Soteria::Credential
- Defined in:
- lib/soteria/credential.rb
Instance Method Summary collapse
-
#authenticate_credentials(client, otp, credentials) ⇒ Hash
Check if a otp is valid for a given credential.
-
#authenticate_user_credential(client, user_id, credential_code) ⇒ Hash
Authenticate a user with a credential.
-
#get_auth_body(otp, credentials) ⇒ Hash
Create the body for the authenticate credentials request.
-
#get_credential_info(client, credential_id, credential_type, include_push) ⇒ Hash
Use getCredentialInfo to get the credential that was last bound to the user, When the credential was last authenticated and the friendly name for the credential.
- #get_return_hash(response_hash) ⇒ Object
-
#get_server_time(client) ⇒ Hash
Use getServerTime to obtain the current server time.
-
#register_sms(client, phone_number) ⇒ Object
Register a SMS credential to the VIP Account.
Instance Method Details
#authenticate_credentials(client, otp, credentials) ⇒ Hash
Check if a otp is valid for a given credential.
72 73 74 75 |
# File 'lib/soteria/credential.rb', line 72 def authenticate_credentials(client, otp, credentials) result = client.call(:authenticate_credentials, message: get_auth_body(otp, credentials)) get_return_hash(result.body[:authenticate_credentials_response]) end |
#authenticate_user_credential(client, user_id, credential_code) ⇒ Hash
Authenticate a user with a credential. A credential includes a physical token, the desktop VIP credential app or the mobile VIP credential app. Users must link their credential id to their user id for this authentication to work.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/soteria/credential.rb', line 26 def authenticate_user_credential(client, user_id, credential_code) result = client.call(:authenticate_user, message: { 'vip:requestId': Utilities.get_request_id('authenticate_user_credential'), 'vip:userId': user_id, 'vip:otpAuthData': { 'vip:otp': credential_code } }) get_return_hash(result.body[:authenticate_user_response]) end |
#get_auth_body(otp, credentials) ⇒ Hash
Create the body for the authenticate credentials request.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/soteria/credential.rb', line 47 def get_auth_body(otp, credentials) credential_array = [] credentials.each do |credential| credential_array.push({'vip:credentialId': credential[:id], 'vip:credentialType': credential[:type]}) end { 'vip:requestId': Utilities.get_request_id('authenticate_credentials'), 'vip:credentials': credential_array, 'vip:otpAuthData': { 'vip:otp': otp } } end |
#get_credential_info(client, credential_id, credential_type, include_push) ⇒ Hash
Use getCredentialInfo to get the credential that was last bound to the user, When the credential was last authenticated and the friendly name for the credential.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/soteria/credential.rb', line 102 def get_credential_info(client, credential_id, credential_type, include_push) = { 'vip:requestId': Utilities.get_request_id('get_credential_info'), 'vip:credentialId': credential_id, 'vip:credentialType': credential_type } unless include_push == nil [:'vip:includePushAttributes'] = include_push end response = client.call(:get_credential_info, message: ) response_hash = response.body[:get_credential_info_response] ret = get_return_hash(response_hash) # get the credential info credential = { id: response_hash[:credential_id], type: response_hash[:credential_type], enabled: response_hash[:credential_status] == 'ENABLED' } # add the bindings if they exist unless response_hash[:num_bindings] == '0' credential[:user_binding] = response_hash[:user_binding_detail] end ret[:credential] = credential ret end |
#get_return_hash(response_hash) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/soteria/credential.rb', line 6 def get_return_hash(response_hash) success = response_hash[:status] == '0000' { success: success, message: response_hash[:status_message], id: response_hash[:request_id], auth_id: response_hash[:authn_id], detail: response_hash[:detail_message] } end |
#get_server_time(client) ⇒ Hash
Use getServerTime to obtain the current server time.
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/soteria/credential.rb', line 140 def get_server_time(client) response = client.call(:get_server_time, message: {'vip:requestId': Utilities.get_request_id('get_server_time')}) response_body = response.body[:get_server_time_response] ret = get_return_hash(response_body) unless response_body[:timestamp] == nil ret[:time] = response_body[:timestamp] end ret end |
#register_sms(client, phone_number) ⇒ Object
Register a SMS credential to the VIP Account. This must be done before you can add a SMS credential to a user.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/soteria/credential.rb', line 82 def register_sms(client, phone_number) result = client.call(:register, message: { 'vip:requestId': Utilities.get_request_id('register_credential'), 'vip:smsDeliveryInfo': { 'vip:phoneNumber': phone_number } } ) get_return_hash(result.body[:register_response]) end |