-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stoiveyp-PinConfirmationHelper'
- Loading branch information
Showing
11 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"type": "Connections.StartConnection", | ||
"uri": "connection://AMAZON.VerifyPerson/2", | ||
"input": { | ||
"requestedAuthenticationConfidenceLevel": { | ||
"level": 400, | ||
"customPolicy": { | ||
"policyName": "VOICE_PIN" | ||
} | ||
} | ||
}, | ||
"token": "example-token" | ||
} |
18 changes: 18 additions & 0 deletions
18
Alexa.NET.Tests/Examples/PinConfirmationSessionResumed.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"type": "SessionResumedRequest", | ||
"requestId": "amzn1.echo-api.request.example", | ||
"timestamp": "2019-10-15T03:15:43Z", | ||
"locale": "en-US", | ||
"cause": { | ||
"type": "ConnectionCompleted", | ||
"token": "Some connection token data", | ||
"status": { | ||
"code": "200", | ||
"message": "Successfully performed PIN confirmation" | ||
}, | ||
"result": { | ||
"status": "NOT_ACHIEVED", | ||
"reason": "VERIFICATION_METHOD_NOT_SETUP" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Alexa.NET.Request; | ||
using Newtonsoft.Json; | ||
|
||
namespace Alexa.NET.ConnectionTasks.Inputs | ||
{ | ||
public class PinConfirmation:IConnectionTask | ||
{ | ||
public const string AssociatedUri = "connection://AMAZON.VerifyPerson/2"; | ||
|
||
//https://developer.amazon.com/en-US/docs/alexa/custom-skills/pin-confirmation-for-alexa-skills.html#connections-startconnection-format | ||
[JsonIgnore] | ||
public string ConnectionUri => AssociatedUri; | ||
|
||
[JsonProperty("requestedAuthenticationConfidenceLevel")] | ||
public AuthenticationConfidenceLevel RequestedAuthenticationConfidenceLevel { get; } = | ||
new AuthenticationConfidenceLevel { | ||
Level = 400, | ||
Custom = new AuthenticationConfidenceLevelCustomPolicy("VOICE_PIN") | ||
|
||
}; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Alexa.NET/ConnectionTasks/Inputs/PinConfirmationConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Linq; | ||
using Alexa.NET.Request.Type; | ||
using Alexa.NET.Response.Converters; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Alexa.NET.ConnectionTasks.Inputs | ||
{ | ||
public class PinConfirmationConverter : IConnectionTaskConverter | ||
{ | ||
private static readonly JsonSerializer Serializer = JsonSerializer.Create(); | ||
|
||
public bool CanConvert(JObject jObject) | ||
{ | ||
return jObject.ContainsKey("uri") && | ||
jObject.GetValue("uri").Value<string>() == PinConfirmation.AssociatedUri; | ||
} | ||
|
||
public IConnectionTask Convert(JObject jObject) | ||
{ | ||
var task = new PinConfirmation(); | ||
Serializer.Populate(jObject.CreateReader(), task); | ||
return task; | ||
} | ||
|
||
public static void AddToConnectionTaskConverters() | ||
{ | ||
if (ConnectionTaskConverter.ConnectionTaskConverters.Where(rc => rc != null) | ||
.All(rc => rc.GetType() != typeof(PinConfirmationConverter))) | ||
{ | ||
ConnectionTaskConverter.ConnectionTaskConverters.Add(new PinConfirmationConverter()); | ||
} | ||
} | ||
|
||
public static PinConfirmationResult ResultFromSessionResumed(SessionResumedRequest request) | ||
{ | ||
if (request.Cause.Result is JObject jo) | ||
{ | ||
var task = new PinConfirmationResult(); | ||
Serializer.Populate(jo.CreateReader(), task); | ||
return task; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Alexa.NET.ConnectionTasks.Inputs | ||
{ | ||
public enum PinConfirmationReason | ||
{ | ||
[EnumMember(Value = "METHOD_LOCKOUT")] MethodLockout, | ||
|
||
[EnumMember(Value = "VERIFICATION_METHOD_NOT_SETUP")] | ||
VerificationMethodNotSetup, | ||
[EnumMember(Value = "NOT_MATCH")] NotMatch | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Alexa.NET.ConnectionTasks.Inputs | ||
{ | ||
public class PinConfirmationResult | ||
{ | ||
[JsonProperty("status",NullValueHandling = NullValueHandling.Ignore)] | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public PinConfirmationStatus Status { get; set; } | ||
|
||
[JsonProperty("reason",NullValueHandling = NullValueHandling.Ignore)] | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public PinConfirmationReason Reason { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Alexa.NET.ConnectionTasks.Inputs | ||
{ | ||
public enum PinConfirmationStatus | ||
{ | ||
[EnumMember(Value = "ACHIEVED")] Achieved, | ||
[EnumMember(Value = "NOT_ACHIEVED")] NotAchieved, | ||
[EnumMember(Value = "NOT_ENABLED")] NotEnabled | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Alexa.NET.Request | ||
{ | ||
public class AuthenticationConfidenceLevel | ||
{ | ||
[JsonProperty("level")] | ||
public int Level { get; set; } | ||
|
||
[JsonProperty("customPolicy",NullValueHandling = NullValueHandling.Ignore)] | ||
public AuthenticationConfidenceLevelCustomPolicy Custom { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Alexa.NET/Request/AuthenticationConfidenceLevelCustomPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Alexa.NET.Request | ||
{ | ||
public class AuthenticationConfidenceLevelCustomPolicy | ||
{ | ||
public AuthenticationConfidenceLevelCustomPolicy(){} | ||
|
||
public AuthenticationConfidenceLevelCustomPolicy(string policyName) | ||
{ | ||
PolicyName = policyName; | ||
} | ||
|
||
[JsonProperty("policyName")] | ||
public string PolicyName { get; set; } | ||
} | ||
} |