public void SetupSharingProfileShouldReturnToken() { string tokenValue = "kyHPjq2+Y48cx+9yS/XzmW09jVUylSdhbP+3Q9Tc9p6bCEnyfa8vj38"; using (var httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("{\"token\": \"" + tokenValue + "\"}") }) { SandboxClient yotiSandboxClient; Mock <HttpMessageHandler> handlerMock = HttpMock.SetupMockMessageHandler(httpResponseMessage); using var httpClient = new HttpClient(handlerMock.Object); yotiSandboxClient = new SandboxClientBuilder(httpClient) .WithClientSdkId(_someSdkId) .WithKeyPair(KeyPair.Get()) .Build(); string result = yotiSandboxClient.SetupSharingProfile( _yotiTokenRequest); Assert.Equal(tokenValue, result); }; }
public void SetupSharingProfileShouldThrowForNonSuccessCode() { using (var httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("{}") }) { SandboxClient yotiSandboxClient; Mock <HttpMessageHandler> handlerMock = HttpMock.SetupMockMessageHandler(httpResponseMessage); using var httpClient = new HttpClient(handlerMock.Object); yotiSandboxClient = new SandboxClientBuilder(httpClient) .WithClientSdkId(_someSdkId) .WithKeyPair(KeyPair.Get()) .Build(); var exception = Assert.Throws <SandboxException>(() => { yotiSandboxClient.SetupSharingProfile( _yotiTokenRequest); }); Assert.Contains("Error when setting up sharing profile", exception.Message, StringComparison.Ordinal); }; }
public static void BuilderShouldCreateClient() { var sandboxClient = new SandboxClientBuilder() .WithClientSdkId(_someSdkId) .WithKeyPair(KeyPair.Get()) .WithApiUri(_someUri) .Build(); Assert.NotNull(sandboxClient); }
public void TestDocScan() { Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair sandboxKeyPair; using (StreamReader stream = File.OpenText("path/to/hub-private-key.pem")) { sandboxKeyPair = Yoti.Auth.CryptoEngine.LoadRsaKey(stream); } const string sandboxClientSdkid = "your SDK ID"; var responseConfig = new ResponseConfigBuilder() .WithCheckReports( new SandboxCheckReportsBuilder() .WithAsyncReportDelay(10) .WithDocumentAuthenticityCheck( new SandboxDocumentAuthenticityCheckBuilder() .WithBreakdown( (new SandboxBreakdownBuilder()) .WithSubCheck("security_features") .WithResult("NOT_AVAILABLE") .WithDetail(new SandboxDetail("some_detail", "some_detail_value")) .Build() ) .WithRecommendation( (new SandboxRecommendationBuilder()) .WithValue("NOT_AVAILABLE") .WithReason("PICTURE_TOO_DARK") .WithRecoverySuggestion("BETTER_LIGHTING") .Build() ) .Build() ) .WithDocumentFaceMatchCheck( new SandboxDocumentFaceMatchCheckBuilder() .WithBreakdown( (new SandboxBreakdownBuilder()) .WithSubCheck("security_features") .WithResult("PASS") .Build() ) .WithRecommendation( (new SandboxRecommendationBuilder()) .WithValue("APPROVE") .Build() ) .Build() ) .WithDocumentTextDataCheck( new SandboxDocumentTextDataCheckBuilder() .WithDocumentFields( new Dictionary <string, object> { { "full_name", "John Doe" }, { "nationality", "GBR" }, { "date_of_birth", "1986-06-01" }, { "document_number", "123456789" } }) .WithBreakdown( new SandboxBreakdownBuilder() .WithSubCheck("document_in_date") .WithResult("PASS") .Build() ) .WithRecommendation( new SandboxRecommendationBuilder() .WithValue("APPROVE") .Build() ) .Build() ) .WithLivenessCheck( new SandboxZoomLivenessCheckBuilder() .WithBreakdown( new SandboxBreakdownBuilder() .WithSubCheck("security_features") .WithResult("PASS") .Build() ) .WithRecommendation( new SandboxRecommendationBuilder() .WithValue("APPROVE") .Build() ) .Build() ) .Build() ) .WithTaskResults( new SandboxTaskResultsBuilder() .WithDocumentTextDataExtractionTask( new SandboxDocumentTextDataExtractionTaskBuilder() .WithDocumentFields( new Dictionary <string, object> { { "full_name", "John Doe" }, { "nationality", "GBR" }, { "date_of_birth", "1986-06-01" }, { "document_number", "123456789" } }) .Build() ) .Build() ) .Build(); var client = new SandboxClientBuilder() .WithClientSdkId(sandboxClientSdkid) .WithKeyPair(sandboxKeyPair) .Build(); client.ConfigureSessionResponse("SESSION_ID", responseConfig); }
public void TestProfile() { Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair sandboxKeyPair; using (StreamReader stream = File.OpenText("path/to/hub-private-key.pem")) { sandboxKeyPair = Yoti.Auth.CryptoEngine.LoadRsaKey(stream); } const string sandboxClientSdkid = "your SDK ID"; SandboxClient sandboxClient = new SandboxClientBuilder() .WithClientSdkId(sandboxClientSdkid) .WithKeyPair(sandboxKeyPair) .Build(); SandboxAgeVerification ageVerification = new SandboxAgeVerificationBuilder() .WithDateOfBirth(new DateTime(2001, 12, 31)) .WithAgeOver(18) .Build(); DateTime expiryDate = DateTime.UtcNow.AddDays(1); var documentImages = new SandboxDocumentImagesBuilder() .WithJpegContent(Encoding.UTF8.GetBytes("some JPEG content")) .WithPngContent(Encoding.UTF8.GetBytes("some PNG content")) .Build(); SandboxExtraData sandboxExtraData = new SandboxExtraDataBuilder() .WithDataEntry( new SandboxAttributeIssuanceDetailsBuilder() .WithDefinition("attribute.name") .WithExpiryDate(expiryDate) .WithIssuanceToken("some-issuance-token") .Build()) .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") .WithDocumentImages(documentImages) .WithExtraData(sandboxExtraData) .Build(); var sandboxOneTimeUseToken = sandboxClient.SetupSharingProfile(tokenRequest); var yotiClient = new YotiClient(new HttpClient(), sandboxClientSdkid, sandboxKeyPair); 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()); }