-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from getyoti/development
Release v1.0.0: Expose Sandbox
- Loading branch information
Showing
33 changed files
with
2,376 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 1 | ||
update_configs: | ||
- package_manager: "dotnet:nuget" | ||
directory: "/" | ||
update_schedule: "live" | ||
target_branch: "development" | ||
|
||
default_reviewers: | ||
- "echarrod" | ||
- "davidgrayston" | ||
- "MrBurtyyy" | ||
|
||
default_assignees: ["echarrod"] |
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,4 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
*.cs diff=csharp |
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||
</packageSources> | ||
<config> | ||
<add key="repositoryPath" value="packages" /> | ||
</config> | ||
</configuration> |
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 +1,92 @@ | ||
# yoti-dotnet-sdk-sandbox | ||
# Yoti .NET Sandbox SDK | ||
|
||
[](https://dev.azure.com/yoti/Dotnet%20SDK%20Sandbox/_build/latest?definitionId=9&branchName=master) | ||
|
||
Welcome to the Yoti .NET Sandbox. This repo contains the tools you need to test your .NET back-end integration, alongside installation of the [Yoti .NET SDK](https://github.com/getyoti/yoti-dotnet-sdk). | ||
|
||
## Sandbox Supported Frameworks | ||
- .NET Standard 2.1 | ||
- .NET Core App 3.1 | ||
- .NET 4.8 | ||
|
||
Please email [[email protected]](mailto:[email protected]) if you require a Target Framework which is not listed here. | ||
|
||
## Installing the Sandbox | ||
|
||
To install the Yoti Sandbox NuGet package you will need to install NuGet. You can find instructions to do that [here](http://docs.nuget.org/ndocs/guides/install-nuget) | ||
|
||
To import the latest Yoti SDK into your project, enter the following command from NuGet Package Manager Console in Visual Studio: | ||
|
||
``` | ||
Install-Package Yoti.Sandbox | ||
``` | ||
|
||
For other installation methods, see [nuget.org/packages/Yoti.Sandbox](https://www.nuget.org/packages/Yoti.Sandbox) | ||
|
||
## Configuration | ||
|
||
* `CLIENT_SDK_ID` is the SDK identifier generated by Yoti Hub in the Key tab when you create your app. | ||
|
||
* `/path/to/your-pem-file.pem` is the path to the application pem file. It can be downloaded only once from the Keys tab in your Yoti Hub. | ||
|
||
Please do not open the pem file as this might corrupt the key and you will need to create a new application. | ||
|
||
## Profile Token Creation | ||
|
||
```cs | ||
Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair keyPair; | ||
|
||
using (StreamReader stream = File.OpenText("path/to/hub-private-key.pem")) | ||
{ | ||
keyPair = Yoti.Auth.CryptoEngine.LoadRsaKey(stream); | ||
} | ||
|
||
const string sandboxClientSdkid = "your SDK ID"; | ||
|
||
SandboxClient sandboxClient = new SandboxClientBuilder() | ||
.WithClientSdkId(sandboxClientSdkid) | ||
.WithKeyPair(keyPair) | ||
.Build(); | ||
|
||
SandboxAgeVerification ageVerification = new SandboxAgeVerificationBuilder() | ||
.WithDateOfBirth(new DateTime(2001, 12, 31)) | ||
.WithAgeOver(18) | ||
.Build(); | ||
|
||
YotiTokenRequest tokenRequest = new YotiTokenRequestBuilder() | ||
.WithRememberMeId("some Remember Me ID") | ||
.WithGivenNames("some given names") | ||
.WithFamilyName("some family name") | ||
.WithFullName("some full name") | ||
.WithDateOfBirth(new DateTime(1980, 10, 30)) | ||
.WithAgeVerification(ageVerification) | ||
.WithGender("some gender") | ||
.WithPhoneNumber("some phone number") | ||
.WithNationality("some nationality") | ||
.WithStructuredPostalAddress(Newtonsoft.Json.JsonConvert.SerializeObject(new | ||
{ | ||
building_number = 1, | ||
address_line1 = "some address" | ||
})) | ||
.WithBase64Selfie(Convert.ToBase64String(Encoding.UTF8.GetBytes("some base64 encoded selfie"))) | ||
.WithEmailAddress("some@email") | ||
.WithDocumentDetails("PASSPORT USA 1234abc") | ||
.Build(); | ||
|
||
var sandboxOneTimeUseToken = sandboxClient.SetupSharingProfile(tokenRequest); | ||
|
||
var yotiClient = new YotiClient(new HttpClient(), sandboxClientSdkid, keyPair); | ||
|
||
Uri sandboxUri = new UriBuilder( | ||
"https", | ||
"api.yoti.com", | ||
443, | ||
"sandbox/v1").Uri; | ||
|
||
yotiClient.OverrideApiUri(sandboxUri); | ||
|
||
ActivityDetails activityDetails = yotiClient.GetActivityDetails(sandboxOneTimeUseToken); | ||
|
||
// Perform tests | ||
Assert.AreEqual("some@email", activityDetails.Profile.EmailAddress.GetValue()); | ||
``` |
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,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29905.134 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yoti.Auth.Sandbox.Tests", "Yoti.Auth.Sandbox.Tests\Yoti.Auth.Sandbox.Tests.csproj", "{21B6EF84-BF27-4353-8753-1BCA438FBDA8}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yoti.Auth.Sandbox", "Yoti.Auth.Sandbox\Yoti.Auth.Sandbox.csproj", "{6D33D6EA-CD5B-4A17-AB30-541C493E7BC9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{21B6EF84-BF27-4353-8753-1BCA438FBDA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{21B6EF84-BF27-4353-8753-1BCA438FBDA8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{21B6EF84-BF27-4353-8753-1BCA438FBDA8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{21B6EF84-BF27-4353-8753-1BCA438FBDA8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{6D33D6EA-CD5B-4A17-AB30-541C493E7BC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6D33D6EA-CD5B-4A17-AB30-541C493E7BC9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6D33D6EA-CD5B-4A17-AB30-541C493E7BC9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6D33D6EA-CD5B-4A17-AB30-541C493E7BC9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A84C8AAE-2EC8-4AD0-8661-0E7E99FA542C} | ||
EndGlobalSection | ||
EndGlobal |
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,14 @@ | ||
using System.IO; | ||
using Org.BouncyCastle.Crypto; | ||
|
||
namespace Yoti.Auth.Tests.Common | ||
{ | ||
public static class KeyPair | ||
{ | ||
public static AsymmetricCipherKeyPair Get() | ||
{ | ||
using StreamReader stream = File.OpenText("test-key.pem"); | ||
return CryptoEngine.LoadRsaKey(stream); | ||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
Yoti.Auth.Sandbox.Tests/Profile/Request/Attribute/Derivation/SandboxAgeVerificationTests.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,128 @@ | ||
using System; | ||
using Xunit; | ||
using Yoti.Auth.Sandbox.Profile.Request.Attribute; | ||
using Yoti.Auth.Sandbox.Profile.Request.Attribute.Derivation; | ||
|
||
namespace Yoti.Auth.Sandbox.Tests.Profile.Request.Attribute.Derivation | ||
{ | ||
public static class SandboxAgeVerificationTests | ||
{ | ||
private const string _validDateString = "1980-08-05"; | ||
private static readonly DateTime _validDate = new DateTime(1980, 8, 5); | ||
|
||
[Fact] | ||
public static void ShouldErrorForBadDateOfBirth() | ||
{ | ||
var exception = Assert.Throws<InvalidCastException>(() => | ||
{ | ||
SandboxAgeVerification.Builder() | ||
.WithDateOfBirth("2011-15-35") | ||
.Build(); | ||
}); | ||
|
||
Assert.Contains("Error when converting string value '2011-15-35' to a DateTime", exception.Message, StringComparison.Ordinal); | ||
} | ||
|
||
[Fact] | ||
public static void ShouldErrorForNullAnchors() | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(() => | ||
{ | ||
SandboxAgeVerification.Builder() | ||
.WithAnchors(null); | ||
}); | ||
|
||
Assert.Contains("Value cannot be null.", exception.Message, StringComparison.Ordinal); | ||
Assert.Contains("Parameter 'anchors'", exception.Message, StringComparison.Ordinal); | ||
} | ||
|
||
[Fact] | ||
public static void ShouldErrorForMissingDateOfBirth() | ||
{ | ||
var exception = Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
SandboxAgeVerification.Builder() | ||
.Build(); | ||
}); | ||
|
||
Assert.Contains( | ||
"the value of 'dateOfBirth' must not be equal to the default value for 'System.DateTime'", | ||
exception.Message, | ||
StringComparison.Ordinal); | ||
} | ||
|
||
[Fact] | ||
public static void ShouldErrorForMissingDerivation() | ||
{ | ||
var exception = Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
SandboxAgeVerification.Builder() | ||
.WithDateOfBirth(_validDateString) | ||
.Build(); | ||
}); | ||
|
||
Assert.Contains("'supportedAgeDerivation' must not be empty or null", exception.Message, StringComparison.Ordinal); | ||
} | ||
|
||
[Fact] | ||
public static void ShouldParseDateOfBirthSuccessfully() | ||
{ | ||
SandboxAgeVerification result = SandboxAgeVerification.Builder() | ||
.WithDateOfBirth(_validDateString) | ||
.WithAgeOver(7) | ||
.Build(); | ||
|
||
Assert.Equal(_validDateString, result.ToAttribute().Value); | ||
} | ||
|
||
[Fact] | ||
public static void ShouldCreateAgeOverSandboxAttribute() | ||
{ | ||
SandboxAttribute result = SandboxAgeVerification.Builder() | ||
.WithDateOfBirth(_validDateString) | ||
.WithAgeOver(21) | ||
.Build() | ||
.ToAttribute(); | ||
|
||
Assert.Equal(Constants.UserProfile.DateOfBirthAttribute, result.Name); | ||
Assert.Equal(_validDateString, result.Value); | ||
Assert.Equal($"{Constants.UserProfile.AgeOverAttribute}:{21}", result.Derivation); | ||
Assert.Equal("False", result.Optional); | ||
Assert.Empty(result.Anchors); | ||
} | ||
|
||
[Fact] | ||
public static void ShouldCreateAgeUnderSandboxAttribute() | ||
{ | ||
SandboxAttribute result = SandboxAgeVerification.Builder() | ||
.WithDateOfBirth(_validDateString) | ||
.WithAgeUnder(16) | ||
.Build() | ||
.ToAttribute(); | ||
|
||
Assert.Equal(Constants.UserProfile.DateOfBirthAttribute, result.Name); | ||
Assert.Equal(_validDateString, result.Value); | ||
Assert.Equal($"{Constants.UserProfile.AgeUnderAttribute}:{16}", result.Derivation); | ||
Assert.Equal("False", result.Optional); | ||
Assert.Empty(result.Anchors); | ||
} | ||
|
||
[Fact] | ||
public static void ShouldCreateAgeVerificationWithAnchors() | ||
{ | ||
SandboxAnchor sandboxAnchor = SandboxAnchor.Builder().Build(); | ||
SandboxAttribute result = SandboxAgeVerification.Builder() | ||
.WithDateOfBirth(_validDate) | ||
.WithAgeUnder(16) | ||
.WithAnchors(new System.Collections.Generic.List<SandboxAnchor> { sandboxAnchor }) | ||
.Build() | ||
.ToAttribute(); | ||
|
||
Assert.Equal(Constants.UserProfile.DateOfBirthAttribute, result.Name); | ||
Assert.Equal(_validDateString, result.Value); | ||
Assert.Equal($"{Constants.UserProfile.AgeUnderAttribute}:{16}", result.Derivation); | ||
Assert.Equal("False", result.Optional); | ||
Assert.Equal(new System.Collections.Generic.List<SandboxAnchor> { sandboxAnchor }, result.Anchors); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
Yoti.Auth.Sandbox.Tests/Profile/Request/Attribute/SandboxAnchorTests.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,77 @@ | ||
using System; | ||
using Xunit; | ||
using Yoti.Auth.Sandbox.Profile.Request.Attribute; | ||
|
||
namespace Yoti.Auth.Sandbox.Tests.Profile.Request.Attribute | ||
{ | ||
public static class SandboxAnchorTests | ||
{ | ||
private static SandboxAnchorBuilder _builder; | ||
|
||
[Fact] | ||
public static void BuilderShouldSetEnumType() | ||
{ | ||
_builder = SandboxAnchor.Builder(); | ||
|
||
_builder.WithType(Anchors.AnchorType.SOURCE); | ||
SandboxAnchor result = _builder.Build(); | ||
|
||
Assert.Equal("SOURCE", result.Type); | ||
} | ||
|
||
[Fact] | ||
public static void BuilderShouldSetStringType() | ||
{ | ||
string type = "SOURCE"; | ||
|
||
_builder = SandboxAnchor.Builder(); | ||
|
||
_builder.WithType(type); | ||
SandboxAnchor result = _builder.Build(); | ||
|
||
Assert.Equal(type, result.Type); | ||
} | ||
|
||
[Fact] | ||
public static void BuilderShouldSetValue() | ||
{ | ||
string value = "value"; | ||
|
||
_builder = SandboxAnchor.Builder(); | ||
|
||
_builder.WithValue(value); | ||
SandboxAnchor result = _builder.Build(); | ||
|
||
Assert.Equal(value, result.Value); | ||
} | ||
|
||
[Fact] | ||
public static void BuilderShouldSetSubType() | ||
{ | ||
string subType = "subType"; | ||
|
||
_builder = SandboxAnchor.Builder(); | ||
|
||
_builder.WithSubType(subType); | ||
SandboxAnchor result = _builder.Build(); | ||
|
||
Assert.Equal(subType, result.SubType); | ||
} | ||
|
||
[Fact] | ||
public static void BuilderShouldSetTimestamp() | ||
{ | ||
DateTime timestamp = new DateTime(2019, 12, 31, 23, 59, 59, DateTimeKind.Utc); | ||
|
||
DateTimeOffset dto = new DateTimeOffset(timestamp); | ||
var expectedUnixTime = dto.ToUnixTimeMilliseconds() * 1000; | ||
|
||
_builder = SandboxAnchor.Builder(); | ||
|
||
_builder.WithTimestamp(timestamp); | ||
SandboxAnchor result = _builder.Build(); | ||
|
||
Assert.Equal(expectedUnixTime, result.UnixMicrosecondTimestamp); | ||
} | ||
} | ||
} |
Oops, something went wrong.