Skip to content

Commit 53b24ed

Browse files
committed
Merge pull request #8 from illiminable/master
Two-way support and remove limit on leading zeroes.
2 parents 663cb8d + 4596e0f commit 53b24ed

File tree

14 files changed

+415
-31
lines changed

14 files changed

+415
-31
lines changed

docs/Web_Services.aml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,42 @@
121121
</para>
122122
</entry>
123123
</row>
124+
<row>
125+
<entry>
126+
<para>
127+
<legacyBold>Push</legacyBold>
128+
</para>
129+
</entry>
130+
<entry>
131+
<para>
132+
Delivery authorization requests to your users via Push Notification, and then by receiving their permission responses via their mobile device’s wireless Internet connection.
133+
</para>
134+
</entry>
135+
</row>
136+
<row>
137+
<entry>
138+
<para>
139+
<legacyBold>SoftToken</legacyBold>
140+
</para>
141+
</entry>
142+
<entry>
143+
<para>
144+
Authenticate your end users when they use the TeleSign AuthID application on their mobile device to generate a Time-based One-time Password (TOTP) verification code
145+
</para>
146+
</entry>
147+
</row>
148+
<row>
149+
<entry>
150+
<para>
151+
<legacyBold>TwoWaySms</legacyBold>
152+
</para>
153+
</entry>
154+
<entry>
155+
<para>
156+
Authenticate your users and verify user transactions via two-way Short Message Service (SMS) wireless communication
157+
</para>
158+
</entry>
159+
</row>
124160
</table>
125161
</entry>
126162
</row>

src/TeleSign.Services.PhoneId/RawPhoneIdService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ public class RawPhoneIdService : TeleSignService
5151
/// </summary>
5252
private const string LiveResourceFormatString = "/v1/phoneid/live/{0}";
5353

54-
/// <summary>
55-
/// The default value for a use case id if not specified.
56-
/// </summary>
57-
private const string DefaultUseCaseId = "othr";
58-
5954
/// <summary>
6055
/// Initializes a new instance of the RawPhoneIdService class with a supplied credential and uri.
6156
/// </summary>

src/TeleSign.Services.UnitTests/BasePhoneIdResponseParserTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void TestValidPhoneIdScoreParsing()
2424

2525
Assert.AreEqual(response.Errors.Count, 0);
2626
Assert.AreEqual(response.ReferenceId, "013890676FB7010BE1D4494A0000000E");
27-
Assert.AreEqual(response.ResourceUri, null);
27+
Assert.AreEqual(response.ResourceUri, string.Empty);
2828
Assert.AreNotEqual(response.RawResponse, null);
2929
Assert.AreEqual(response.SubResource, "score");
3030

@@ -62,7 +62,7 @@ public void TestValidPhoneIdStandardParsing()
6262

6363
Assert.AreEqual(response.Errors.Count, 0);
6464
Assert.AreEqual(response.ReferenceId, "01389064DBCE010BE1D449490000000E");
65-
Assert.AreEqual(response.ResourceUri, null);
65+
Assert.AreEqual(response.ResourceUri, string.Empty);
6666
Assert.AreNotEqual(response.RawResponse, null);
6767
Assert.AreEqual(response.SubResource, "standard");
6868

@@ -115,7 +115,7 @@ public void TestValidPhoneIdContactNoMatchParsing()
115115
PhoneIdContactResponse response = this.CreateParser().ParsePhoneIdContactResponse(json);
116116

117117
Assert.AreEqual(response.ReferenceId, "013890689D26010BE1D4494700000010");
118-
Assert.AreEqual(response.ResourceUri, null);
118+
Assert.AreEqual(response.ResourceUri, string.Empty);
119119
Assert.AreNotEqual(response.RawResponse, null);
120120
Assert.AreEqual(response.SubResource, "contact");
121121

@@ -173,7 +173,7 @@ public void TestValidPhoneIdContactMatchParsing()
173173

174174
Assert.AreEqual(response.Errors.Count, 0);
175175
Assert.AreEqual(response.ReferenceId, "0138906A9011010BE1D4494B0000000E");
176-
Assert.AreEqual(response.ResourceUri, null);
176+
Assert.AreEqual(response.ResourceUri, string.Empty);
177177
Assert.AreNotEqual(response.RawResponse, null);
178178
Assert.AreEqual(response.SubResource, "contact");
179179

@@ -236,7 +236,7 @@ public void TestValidPhoneIdLiveNoMatchParsing()
236236
PhoneIdLiveResponse response = this.CreateParser().ParsePhoneIdLiveResponse(json);
237237

238238
Assert.AreEqual(response.ReferenceId, "013B23ED8EC2010BE4D40E410000006B");
239-
Assert.AreEqual(response.ResourceUri, null);
239+
Assert.AreEqual(response.ResourceUri, string.Empty);
240240
Assert.AreNotEqual(response.RawResponse, null);
241241
Assert.AreEqual(response.SubResource, "live");
242242

@@ -293,7 +293,7 @@ public void TestValidPhoneIdLiveMatchParsing()
293293
PhoneIdLiveResponse response = this.CreateParser().ParsePhoneIdLiveResponse(json);
294294

295295
Assert.AreEqual(response.ReferenceId, "013B23B1FCCB010BE4D40D4D0000005F");
296-
Assert.AreEqual(response.ResourceUri, null);
296+
Assert.AreEqual(response.ResourceUri, string.Empty);
297297
Assert.AreNotEqual(response.RawResponse, null);
298298
Assert.AreEqual(response.SubResource, "live");
299299

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"reference_id": "013890676FB7010BE1D4494A0000000E", "resource_uri": null, "sub_resource": "score", "status": {"updated_on": "2012-07-16T15:28:14.349203Z", "code": 300, "description": "Transaction successfully completed"}, "errors": [], "numbering": {"original": {"complete_phone_number": "13107409700", "country_code":"1", "phone_number": "3107409700"}, "cleansing": {"call": {"country_code": "1","phone_number": "3107409700", "cleansed_code": 100, "max_length": 10, "min_length": 10}, "sms": {"country_code": "1", "phone_number": "3107409700", "cleansed_code": 100, "max_length": 10, "min_length": 10}}}, "risk": {"level": "low", "recommendation": "allow", "score": 0}}
1+
{"reference_id": "013890676FB7010BE1D4494A0000000E", "resource_uri": null, "sub_resource": "score", "status": {"updated_on": "2012-07-16T15:28:14.349203Z", "code": 300, "description": "Transaction successfully completed"}, "errors": [], "location": {"city": "Los Angeles", "state": "CA", "zip": "90066", "metro_code": "4480", "county": "Los Angeles", "country": {"name": "United States", "iso2": "US", "iso3": "USA"}, "coordinates": {"latitude": 33.99791, "longitude": -118.42302}, "time_zone": {"name": "America/Los_Angeles", "utc_offset_min": "-8", "utc_offset_max": "-8"}}, "numbering": {"original": {"complete_phone_number": "13107409700", "country_code":"1", "phone_number": "3107409700"}, "cleansing": {"call": {"country_code": "1","phone_number": "3107409700", "cleansed_code": 100, "max_length": 10, "min_length": 10}, "sms": {"country_code": "1", "phone_number": "3107409700", "cleansed_code": 100, "max_length": 10, "min_length": 10}}}, "risk": {"level": "low", "recommendation": "allow", "score": 0}, "phone_type": {"code": "1", "description": "FIXED_LINE"}}

src/TeleSign.Services.Verify/JsonDotNetVerifyResponseParser.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ private CodeState ParseCodeState(string codeStateString)
7272

7373
if (!Enum.TryParse<CodeState>(codeStateString, true, out codeState))
7474
{
75-
codeState = CodeState.Other;
75+
if (codeStateString == "VALID_YES")
76+
{
77+
codeState = CodeState.Valid;
78+
}
79+
else
80+
{
81+
codeState = CodeState.Other;
82+
}
7683
}
7784

7885
return codeState;

src/TeleSign.Services.Verify/RawVerifyService.cs

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,98 @@ public string CallRaw(
119119
null,
120120
language);
121121
}
122+
123+
/////// <summary>
124+
/////// The TeleSign Verify Soft Token web service is a server-side component of the TeleSign AuthID application, and it allows you to authenticate your end users when they use the TeleSign AuthID application on their mobile device to generate a Time-based One-time Password (TOTP) verification code
125+
/////// </summary>
126+
/////// <param name="phoneNumber">The phone number for the Verify Soft Token request, including country code</param>
127+
/////// <param name="softTokenId">
128+
/////// The alphanumeric string that uniquely identifies your TeleSign soft token subscription
129+
/////// </param>
130+
/////// <param name="verifyCode">
131+
/////// The verification code received from the end user
132+
/////// </param>
133+
/////// <returns>The raw JSON response from the REST API.</returns>
134+
////public string SoftTokenRaw(
135+
//// string phoneNumber,
136+
//// string softTokenId = null,
137+
//// string verifyCode = null)
138+
////{
139+
//// phoneNumber = this.CleanupPhoneNumber(phoneNumber);
140+
141+
//// if (softTokenId == null)
142+
//// {
143+
//// softTokenId = string.Empty;
144+
//// }
145+
146+
//// if (verifyCode == null)
147+
//// {
148+
//// verifyCode = string.Empty;
149+
//// }
150+
151+
//// Dictionary<string, string> args = ConstructVerifyArgs(
152+
//// VerificationMethod.SoftToken,
153+
//// phoneNumber,
154+
//// softTokenId,
155+
//// verifyCode);
156+
157+
//// string resourceName = string.Format(
158+
//// RawVerifyService.VerifyResourceFormatString,
159+
//// VerificationMethod.SoftToken.ToString().ToLowerInvariant());
160+
161+
//// WebRequest request = this.ConstructWebMobileRequest(
162+
//// resourceName,
163+
//// "POST",
164+
//// args);
165+
166+
//// return this.WebRequester.ReadResponseAsString(request);
167+
////}
168+
169+
/// <summary>
170+
/// The TeleSign Verify 2-Way SMS web service allows you to authenticate your users and verify user transactions via two-way Short Message Service (SMS) wireless communication. Verification requests are sent to user’s in a text message, and users return their verification responses by replying to the text message.
171+
/// </summary>
172+
/// <param name="phoneNumber">The phone number for the Verify Soft Token request, including country code</param>
173+
/// <param name="ucid">
174+
/// A string specifying one of the Use Case Codes
175+
/// </param>
176+
/// <param name="message">
177+
/// The text to display in the body of the text message. You must include the $$CODE$$ placeholder for the verification code somewhere in your message text. TeleSign automatically replaces it with a randomly-generated verification code
178+
/// </param>
179+
/// <param name="validityPeriod">
180+
/// This parameter allows you to place a time-limit on the verification. This provides an extra level of security by restricting the amount of time your end user has to respond (after which, TeleSign automatically rejects their response). Values are expressed as a natural number followed by a lower-case letter that represents the unit of measure. You can use 's' for seconds, 'm' for minutes, 'h' for hours, and 'd' for days
181+
/// </param>
182+
/// <returns>The raw JSON response from the REST API.</returns>
183+
public string TwoWaySmsRaw(
184+
string phoneNumber,
185+
string message,
186+
string validityPeriod = "5m",
187+
string useCaseId = RawVerifyService.DefaultUseCaseId)
188+
{
189+
CheckArgument.NotEmpty(message, "message");
190+
CheckArgument.NotNullOrEmpty(validityPeriod, "validityPeriod");
191+
192+
phoneNumber = this.CleanupPhoneNumber(phoneNumber);
193+
194+
Dictionary<string, string> args = ConstructVerifyArgs(
195+
VerificationMethod.TwoWaySms,
196+
phoneNumber,
197+
null,
198+
message,
199+
null,
200+
validityPeriod,
201+
useCaseId);
202+
203+
string resourceName = string.Format(
204+
RawVerifyService.VerifyResourceFormatString,
205+
"two_way_sms");
206+
207+
WebRequest request = this.ConstructWebRequest(
208+
resourceName,
209+
"POST",
210+
args);
211+
212+
return this.WebRequester.ReadResponseAsString(request);
213+
}
122214

123215
/// <summary>
124216
/// Initiates a PhoneId Push Mobile transaction returning the raw JSON response from
@@ -256,14 +348,23 @@ private static Dictionary<string, string> ConstructVerifyArgs(
256348
string phoneNumber,
257349
string verifyCode,
258350
string messageTemplate,
259-
string language)
351+
string language,
352+
string validityPeriod = null,
353+
string useCaseId = RawVerifyService.DefaultUseCaseId)
260354
{
261355
// TODO: Review code generation rules.
262356
if (verifyCode == null)
263357
{
264358
Random r = new Random();
265359
verifyCode = r.Next(100, 99999).ToString();
266360
}
361+
else
362+
{
363+
if (verificationMethod == VerificationMethod.TwoWaySms)
364+
{
365+
throw new ArgumentException("Verify Code cannot be specified for Two-Way SMS", "verifyCode");
366+
}
367+
}
267368

268369
// TODO: Check code validity here?
269370

@@ -277,17 +378,28 @@ private static Dictionary<string, string> ConstructVerifyArgs(
277378
args.Add("notification_value", verifyCode.ToString());
278379
}
279380
}
381+
else if (verificationMethod == VerificationMethod.TwoWaySms)
382+
{
383+
// Two way sms doesn't take a verify code. So nothing here.
384+
}
280385
else
281386
{
282387
args.Add("verify_code", verifyCode.ToString());
283388
}
389+
284390
args.Add("language", language);
285391

286-
if (verificationMethod == VerificationMethod.Sms || verificationMethod == VerificationMethod.Push)
392+
if (verificationMethod == VerificationMethod.Sms || verificationMethod == VerificationMethod.Push || verificationMethod == VerificationMethod.TwoWaySms)
287393
{
288394
args.Add("template", messageTemplate);
289395
}
290396

397+
if (verificationMethod == VerificationMethod.TwoWaySms)
398+
{
399+
args.Add("validity_period", validityPeriod);
400+
args.Add("ucid", useCaseId);
401+
}
402+
291403
return args;
292404
}
293405
}

src/TeleSign.Services.Verify/VerifyService.cs

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,81 @@ public VerifyResponse SendSms(
170170
x);
171171
}
172172
}
173+
174+
/////// <summary>
175+
/////// The TeleSign Verify Soft Token web service is a server-side component of the TeleSign AuthID application, and it allows you to authenticate your end users when they use the TeleSign AuthID application on their mobile device to generate a Time-based One-time Password (TOTP) verification code
176+
/////// </summary>
177+
/////// <param name="phoneNumber">The phone number for the Verify Soft Token request, including country code</param>
178+
/////// <param name="softTokenId">
179+
/////// The alphanumeric string that uniquely identifies your TeleSign soft token subscription
180+
/////// </param>
181+
/////// <param name="verifyCode">
182+
/////// The verification code received from the end user
183+
/////// </param>
184+
/////// <returns>The raw JSON response from the REST API.</returns>
185+
////public VerifyResponse SendSoftToken(
186+
//// string phoneNumber,
187+
//// string softTokenId = null,
188+
//// string verifyCode = null)
189+
////{
190+
//// phoneNumber = this.CleanupPhoneNumber(phoneNumber);
191+
192+
//// string rawResponse = this.SoftTokenRaw(
193+
//// phoneNumber,
194+
//// softTokenId,
195+
//// verifyCode);
196+
197+
//// try
198+
//// {
199+
//// return this.parser.ParseVerifyResponse(rawResponse);
200+
//// }
201+
//// catch (Exception x)
202+
//// {
203+
//// throw new ResponseParseException(
204+
//// "Error parsing Verify SoftToken response",
205+
//// rawResponse,
206+
//// x);
207+
//// }
208+
////}
209+
210+
/// <summary>
211+
/// The TeleSign Verify 2-Way SMS web service allows you to authenticate your users and verify user transactions via two-way Short Message Service (SMS) wireless communication. Verification requests are sent to user’s in a text message, and users return their verification responses by replying to the text message.
212+
/// </summary>
213+
/// <param name="phoneNumber">The phone number for the Verify Soft Token request, including country code</param>
214+
/// <param name="ucid">
215+
/// A string specifying one of the Use Case Codes
216+
/// </param>
217+
/// <param name="message">
218+
/// The text to display in the body of the text message. You must include the $$CODE$$ placeholder for the verification code somewhere in your message text. TeleSign automatically replaces it with a randomly-generated verification code
219+
/// </param>
220+
/// <param name="validityPeriod">
221+
/// This parameter allows you to place a time-limit on the verification. This provides an extra level of security by restricting the amount of time your end user has to respond (after which, TeleSign automatically rejects their response). Values are expressed as a natural number followed by a lower-case letter that represents the unit of measure. You can use 's' for seconds, 'm' for minutes, 'h' for hours, and 'd' for days
222+
/// </param>
223+
/// <returns>The raw JSON response from the REST API.</returns>
224+
public VerifyResponse SendTwoWaySms(
225+
string phoneNumber,
226+
string message = null,
227+
string validityPeriod = "5m")
228+
{
229+
phoneNumber = this.CleanupPhoneNumber(phoneNumber);
230+
231+
string rawResponse = this.TwoWaySmsRaw(
232+
phoneNumber,
233+
message,
234+
validityPeriod);
235+
236+
try
237+
{
238+
return this.parser.ParseVerifyResponse(rawResponse);
239+
}
240+
catch (Exception x)
241+
{
242+
throw new ResponseParseException(
243+
"Error parsing Verify TwoWaySms response",
244+
rawResponse,
245+
x);
246+
}
247+
}
173248

174249
/// <summary>
175250
/// Initiates a TeleSign Verify transaction via a voice call.
@@ -222,7 +297,6 @@ public VerifyResponse InitiateCall(
222297
/// <param name="language">
223298
/// The language that the message should be in. This parameter is ignored if
224299
/// you supplied a message template.
225-
/// TODO: Details about language string format.
226300
/// </param>
227301
/// <returns>
228302
/// A VerifyResponse object with the status and returned information
@@ -334,16 +408,6 @@ public virtual void ValidateCodeFormat(string verifyCode)
334408
// Empty code is never valid
335409
CheckArgument.NotEmpty(verifyCode, "verifyCode");
336410

337-
// Leading zeros are not allowed.
338-
if (verifyCode[0] == '0')
339-
{
340-
string message = string.Format(
341-
"Verify code '{0}' must not have leading zeroes.",
342-
verifyCode);
343-
344-
throw new ArgumentException(message);
345-
}
346-
347411
foreach (char c in verifyCode)
348412
{
349413
// Only decimal digits are allowed 0-9.

src/TeleSign.Services/TeleSign.config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<TeleSignConfig>
33
<ServiceUri>https://rest.telesign.com</ServiceUri>
4+
<ServiceMobileUri>https://rest-mobile.telesign.com</ServiceMobileUri>
45
<Accounts>
56
<Account name="default">
67
<!-- Enter your customer id and secret key here. -->

0 commit comments

Comments
 (0)