Class: Bandwidth::TwoFactorAuth::MFAController
- Inherits:
-
BaseController
- Object
- BaseController
- Bandwidth::TwoFactorAuth::MFAController
- Defined in:
- lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb
Overview
MFAController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_messaging_two_factor(account_id, body) ⇒ TwoFactorMessagingResponse
Allows a user to send a MFA code through a text message (SMS) Messaging service enabled.
-
#create_verify_two_factor(account_id, body) ⇒ TwoFactorVerifyCodeResponse
Allows a user to verify an MFA code Two-Factor enabled.
-
#create_voice_two_factor(account_id, body) ⇒ TwoFactorVoiceResponse
Allows a user to send a MFA code through a phone call Voice service enabled.
-
#initialize(config, http_call_back: nil) ⇒ MFAController
constructor
A new instance of MFAController.
Methods inherited from BaseController
#execute_request, #validate_parameters, #validate_response
Constructor Details
#initialize(config, http_call_back: nil) ⇒ MFAController
Returns a new instance of MFAController.
10 11 12 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb', line 10 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#create_messaging_two_factor(account_id, body) ⇒ TwoFactorMessagingResponse
Allows a user to send a MFA code through a text message (SMS) Messaging service enabled
81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb', line 81 def create_messaging_two_factor(account_id, body) # Prepare query url. _query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT) _query_builder << '/accounts/{accountId}/code/messaging' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => { 'value' => account_id, 'encode' => false } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) TwoFactorAuthBasicAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise ErrorWithRequestException.new( 'If there is any issue with values passed in by the user', _response ) elsif _response.status_code == 401 raise UnauthorizedRequestException.new( 'Authentication is either incorrect or not present', _response ) elsif _response.status_code == 403 raise ForbiddenRequestException.new( 'The user is not authorized to access this resource', _response ) elsif _response.status_code == 500 raise ErrorWithRequestException.new( 'An internal server error occurred', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) ApiResponse.new( _response, data: TwoFactorMessagingResponse.from_hash(decoded) ) end |
#create_verify_two_factor(account_id, body) ⇒ TwoFactorVerifyCodeResponse
Allows a user to verify an MFA code Two-Factor enabled
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb', line 144 def create_verify_two_factor(account_id, body) # Prepare query url. _query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT) _query_builder << '/accounts/{accountId}/code/verify' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => { 'value' => account_id, 'encode' => false } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) TwoFactorAuthBasicAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise ErrorWithRequestException.new( 'If there is any issue with values passed in by the user', _response ) elsif _response.status_code == 401 raise UnauthorizedRequestException.new( 'Authentication is either incorrect or not present', _response ) elsif _response.status_code == 403 raise ForbiddenRequestException.new( 'The user is not authorized to access this resource', _response ) elsif _response.status_code == 429 raise ErrorWithRequestException.new( 'The user has made too many bad requests and is temporarily locked' \ ' out', _response ) elsif _response.status_code == 500 raise ErrorWithRequestException.new( 'An internal server error occurred', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) ApiResponse.new( _response, data: TwoFactorVerifyCodeResponse.from_hash(decoded) ) end |
#create_voice_two_factor(account_id, body) ⇒ TwoFactorVoiceResponse
Allows a user to send a MFA code through a phone call Voice service enabled
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb', line 19 def create_voice_two_factor(account_id, body) # Prepare query url. _query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT) _query_builder << '/accounts/{accountId}/code/voice' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => { 'value' => account_id, 'encode' => false } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) TwoFactorAuthBasicAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise ErrorWithRequestException.new( 'If there is any issue with values passed in by the user', _response ) elsif _response.status_code == 401 raise UnauthorizedRequestException.new( 'Authentication is either incorrect or not present', _response ) elsif _response.status_code == 403 raise ForbiddenRequestException.new( 'The user is not authorized to access this resource', _response ) elsif _response.status_code == 500 raise ErrorWithRequestException.new( 'An internal server error occurred', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) ApiResponse.new( _response, data: TwoFactorVoiceResponse.from_hash(decoded) ) end |