5
5
6
6
module Bandwidth
7
7
module TwoFactorAuth
8
- # APIController
9
- class APIController < BaseController
8
+ # MFAController
9
+ class MFAController < BaseController
10
10
def initialize ( config , http_call_back : nil )
11
11
super ( config , http_call_back : http_call_back )
12
12
end
13
13
14
- # Two-Factor authentication with Bandwidth Voice services
14
+ # Allows a user to send a MFA code through a phone call
15
15
# @param [String] account_id Required parameter: Bandwidth Account ID with
16
16
# Voice service enabled
17
17
# @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
@@ -44,8 +44,23 @@ def create_voice_two_factor(account_id,
44
44
45
45
# Validate response against endpoint and global error codes.
46
46
if _response . status_code == 400
47
- raise InvalidRequestException . new (
48
- 'client request error' ,
47
+ raise ErrorWithRequestException . new (
48
+ 'If there is any issue with values passed in by the user' ,
49
+ _response
50
+ )
51
+ elsif _response . status_code == 401
52
+ raise UnauthorizedRequestException . new (
53
+ 'Authentication is either incorrect or not present' ,
54
+ _response
55
+ )
56
+ elsif _response . status_code == 403
57
+ raise ForbiddenRequestException . new (
58
+ 'The user is not authorized to access this resource' ,
59
+ _response
60
+ )
61
+ elsif _response . status_code == 500
62
+ raise ErrorWithRequestException . new (
63
+ 'An internal server error occurred' ,
49
64
_response
50
65
)
51
66
end
@@ -58,7 +73,7 @@ def create_voice_two_factor(account_id,
58
73
)
59
74
end
60
75
61
- # Two-Factor authentication with Bandwidth messaging services
76
+ # Allows a user to send a MFA code through a text message (SMS)
62
77
# @param [String] account_id Required parameter: Bandwidth Account ID with
63
78
# Messaging service enabled
64
79
# @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
@@ -91,8 +106,23 @@ def create_messaging_two_factor(account_id,
91
106
92
107
# Validate response against endpoint and global error codes.
93
108
if _response . status_code == 400
94
- raise InvalidRequestException . new (
95
- 'client request error' ,
109
+ raise ErrorWithRequestException . new (
110
+ 'If there is any issue with values passed in by the user' ,
111
+ _response
112
+ )
113
+ elsif _response . status_code == 401
114
+ raise UnauthorizedRequestException . new (
115
+ 'Authentication is either incorrect or not present' ,
116
+ _response
117
+ )
118
+ elsif _response . status_code == 403
119
+ raise ForbiddenRequestException . new (
120
+ 'The user is not authorized to access this resource' ,
121
+ _response
122
+ )
123
+ elsif _response . status_code == 500
124
+ raise ErrorWithRequestException . new (
125
+ 'An internal server error occurred' ,
96
126
_response
97
127
)
98
128
end
@@ -106,7 +136,7 @@ def create_messaging_two_factor(account_id,
106
136
)
107
137
end
108
138
109
- # Verify a previously sent two-factor authentication code
139
+ # Allows a user to verify an MFA code
110
140
# @param [String] account_id Required parameter: Bandwidth Account ID with
111
141
# Two-Factor enabled
112
142
# @param [TwoFactorVerifyRequestSchema] body Required parameter: Example:
@@ -139,8 +169,29 @@ def create_verify_two_factor(account_id,
139
169
140
170
# Validate response against endpoint and global error codes.
141
171
if _response . status_code == 400
142
- raise InvalidRequestException . new (
143
- 'client request error' ,
172
+ raise ErrorWithRequestException . new (
173
+ 'If there is any issue with values passed in by the user' ,
174
+ _response
175
+ )
176
+ elsif _response . status_code == 401
177
+ raise UnauthorizedRequestException . new (
178
+ 'Authentication is either incorrect or not present' ,
179
+ _response
180
+ )
181
+ elsif _response . status_code == 403
182
+ raise ForbiddenRequestException . new (
183
+ 'The user is not authorized to access this resource' ,
184
+ _response
185
+ )
186
+ elsif _response . status_code == 429
187
+ raise ErrorWithRequestException . new (
188
+ 'The user has made too many bad requests and is temporarily locked' \
189
+ ' out' ,
190
+ _response
191
+ )
192
+ elsif _response . status_code == 500
193
+ raise ErrorWithRequestException . new (
194
+ 'An internal server error occurred' ,
144
195
_response
145
196
)
146
197
end
0 commit comments