Class: Cpaas::Twofactor
- Inherits:
-
Object
- Object
- Cpaas::Twofactor
- Defined in:
- lib/cpaas-sdk/resources/twofactor.rb
Overview
CPaaS provides Authentication API where a two-factor authentication (2FA) flow can be implemented by using that.
Class Method Summary collapse
-
.delete_code(params = {}) ⇒ Object
Delete authentication code resource.
-
.resend_code(params = {}) ⇒ Object
Resending the authentication code via same code resource, invalidating the previously sent code.
-
.send_code(params = {}) ⇒ Object
Create a new authentication code.
-
.verify_code(params = {}) ⇒ Object
Verifying authentication code.
Class Method Details
.delete_code(params = {}) ⇒ Object
Delete authentication code resource.
129 130 131 |
# File 'lib/cpaas-sdk/resources/twofactor.rb', line 129 def self.delete_code(params = {}) Cpaas.api.send_request("#{base_url}/codes/#{params[:code_id]}", {}, :delete) end |
.resend_code(params = {}) ⇒ Object
Resending the authentication code via same code resource, invalidating the previously sent code.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cpaas-sdk/resources/twofactor.rb', line 95 def self.resend_code(params = {}) address = (params[:destination_address].is_a? String) ? [ params[:destination_address] ] : params[:destination_address] = { body: { code: { address: address, method: params[:method] || 'sms', format: { length: params[:length] || 6, type: params[:type] || 'numeric' }, expiry: params[:expiry] || 120, subject: params[:subject], message: params[:message] } } } response = Cpaas.api.send_request("#{base_url}/codes/#{params[:code_id]}", , :put) process_response(response) do |res| { code_id: id_from(res.dig(:code, :resource_url)) } end end |
.send_code(params = {}) ⇒ Object
Create a new authentication code.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cpaas-sdk/resources/twofactor.rb', line 21 def self.send_code(params = {}) address = (params[:destination_address].is_a? String) ? [ params[:destination_address] ] : params[:destination_address] = { body: { code: { address: address, method: params[:method] || 'sms', format: { length: params[:length] || 6, type: params[:type] || 'numeric' }, expiry: params[:expiry] || 120, subject: params[:subject], message: params[:message] } } } response = Cpaas.api.send_request("#{base_url}/codes", , :post) process_response(response) do |res| { code_id: id_from(res.dig(:code, :resource_url)) } end end |
.verify_code(params = {}) ⇒ Object
Verifying authentication code
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cpaas-sdk/resources/twofactor.rb', line 56 def self.verify_code(params = {}) = { body: { code: { verify: params[:verification_code] } } } response = Cpaas.api.send_request("#{base_url}/codes/#{params[:code_id]}/verify", , :put) process_response(response) do |res| if res[:status_code] == 204 { verified: true, message: 'Success' } else { verified: false, message: 'Code invalid or expired' } end end end |