コード例 #1
0
        /// <summary>
        /// Asynchronously request a <see cref="ActivityDetails"/>  using the encrypted token provided by yoti during the login process.
        /// </summary>
        /// <param name="encryptedToken">The encrypted returned by Yoti after successfully authenticating.</param>
        /// <returns>The account details of the logged in user as a <see cref="ActivityDetails"/>. </returns>
        public async Task <AmlResult> PerformAmlCheckAsync(string appId, AsymmetricCipherKeyPair keyPair, string apiUrl, IAmlProfile amlProfile)
        {
            if (apiUrl == null)
            {
                throw new ArgumentNullException(nameof(apiUrl));
            }

            if (amlProfile == null)
            {
                throw new ArgumentNullException(nameof(amlProfile));
            }

            string serializedProfile = Newtonsoft.Json.JsonConvert.SerializeObject(amlProfile);

            byte[] httpContent = System.Text.Encoding.UTF8.GetBytes(serializedProfile);

            HttpMethod httpMethod = HttpMethod.Post;

            string endpoint = EndpointFactory.CreateAmlEndpoint(httpMethod, appId);

            Dictionary <string, string> headers = CreateHeaders(keyPair, httpMethod, endpoint, httpContent, contentType: YotiConstants.ContentTypeJson);

            AmlResult result = await Task.Run(async() => await new RemoteAmlService()
                                              .PerformCheck(_httpRequester, amlProfile, headers, apiUrl, endpoint, httpContent));

            return(result);
        }
コード例 #2
0
        public void YotiClientEngine_PerformAmlCheckAsync_Other()
        {
            var    keyPair = GetKeyPair();
            string sdkId   = "fake-sdk-id";

            FakeHttpRequester httpRequester = new FakeHttpRequester((httpClient, httpMethod, uri, headers, byteContent) =>
            {
                return(Task.FromResult(new Response
                {
                    Success = false,
                    StatusCode = (int)HttpStatusCode.Forbidden,
                    Content = "{Content}"
                }));
            });

            YotiClientEngine engine     = new YotiClientEngine(httpRequester);
            AmlProfile       amlProfile = TestTools.Aml.CreateStandardAmlProfile();

            AggregateException aggregateException = Assert.ThrowsException <AggregateException>(() =>
            {
                AmlResult amlResult = engine.PerformAmlCheck(sdkId, keyPair, YotiConstants.DefaultYotiApiUrl, amlProfile);
            });

            Assert.IsTrue(Exceptions.IsExceptionInAggregateException <AmlException>(aggregateException));
        }
コード例 #3
0
        public async Task YotiClientEngine_PerformAmlCheckAsync()
        {
            var    keyPair = GetKeyPair();
            string sdkId   = "fake-sdk-id";

            FakeHttpRequester httpRequester = new FakeHttpRequester((httpClient, httpMethod, uri, headers, byteContent) =>
            {
                return(Task.FromResult(new Response
                {
                    Success = true,
                    StatusCode = 200,
                    Content = "{\"on_fraud_list\":true,\"on_pep_list\":false,\"on_watch_list\":false}"
                }));
            });

            YotiClientEngine engine     = new YotiClientEngine(httpRequester);
            AmlProfile       amlProfile = TestTools.Aml.CreateStandardAmlProfile();

            AmlResult amlResult = await engine.PerformAmlCheckAsync(sdkId, keyPair, YotiConstants.DefaultYotiApiUrl, amlProfile);

            Assert.IsNotNull(amlResult);
            Assert.IsTrue(amlResult.IsOnFraudList());
            Assert.IsFalse(amlResult.IsOnPepList());
            Assert.IsFalse(amlResult.IsOnWatchList());
        }
コード例 #4
0
        private async Task <AmlResult> PerformAmlCheckInternalAsync(string sdkId, AsymmetricCipherKeyPair keyPair, Uri apiUrl, IAmlProfile amlProfile)
        {
            string serializedProfile = Newtonsoft.Json.JsonConvert.SerializeObject(amlProfile);

            byte[] httpContent = System.Text.Encoding.UTF8.GetBytes(serializedProfile);

            AmlResult result = await Task.Run(async() => await new RemoteAmlService()
                                              .PerformCheck(
                                                  _httpClient, keyPair, apiUrl, sdkId, httpContent).ConfigureAwait(false))
                               .ConfigureAwait(false);

            return(result);
        }
コード例 #5
0
        public void YotiClient_PerformAmlCheck_NullAmlProfile_ThrowsException()
        {
            string sdkId            = "fake-sdk-id";
            var    privateStreamKey = GetValidKeyStream();

            YotiClient client = new YotiClient(sdkId, privateStreamKey);

            AggregateException aggregateException = Assert.ThrowsException <AggregateException>(() =>
            {
                AmlResult amlResult = client.PerformAmlCheck(amlProfile: null);
            });

            Assert.IsTrue(Exceptions.IsExceptionInAggregateException <ArgumentNullException>(aggregateException));
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: getyoti/yoti-dotnet-sdk
        private static void Main()
        {
            Console.WriteLine("Yoti AML Example");

            CheckForEnvPresence();

            string sdkId = Environment.GetEnvironmentVariable("YOTI_CLIENT_SDK_ID");

            Console.WriteLine(string.Format("sdkId='{0}'", sdkId));

            string yotiKeyFilePath = Environment.GetEnvironmentVariable("YOTI_KEY_FILE_PATH");

            Console.WriteLine(
                string.Format(
                    "yotiKeyFilePath='{0}'",
                    yotiKeyFilePath));

            using (StreamReader privateKeyStream = File.OpenText(yotiKeyFilePath))
            {
                var yotiClient = new YotiClient(sdkId, privateKeyStream);

                AmlProfile amlProfile;
                if (DotNetEnv.Env.GetBool("USA_EXAMPLE", fallback: false))
                {
                    amlProfile = CreateUsaProfile();
                }
                else
                {
                    amlProfile = CreateGbrProfile();
                }

                AmlResult amlResult = yotiClient.PerformAmlCheck(amlProfile);

                Console.WriteLine(string.Format(
                                      "{0}{0}Completing check for AML profile: '{1}'",
                                      Environment.NewLine,
                                      JsonConvert.SerializeObject(amlProfile, Formatting.Indented)));

                Console.WriteLine(string.Format(
                                      "{0}{0}Result:",
                                      Environment.NewLine));
                Console.WriteLine(string.Format("Is on PEP list: {0}", amlResult.IsOnPepList()));
                Console.WriteLine(string.Format("Is on Fraud list: {0}", amlResult.IsOnFraudList()));
                Console.WriteLine(string.Format("Is on Watch list: {0}", amlResult.IsOnWatchList()));
            }
        }
コード例 #7
0
        public void YotiClient_PerformAmlCheck_NullFamilyName_ThrowsException()
        {
            string sdkId            = "fake-sdk-id";
            var    privateStreamKey = GetValidKeyStream();

            YotiClient client = new YotiClient(sdkId, privateStreamKey);

            AmlProfile amlProfile = new AmlProfile(
                givenNames: "Edward Richard George",
                familyName: null,
                amlAddress: TestTools.Aml.CreateStandardAmlAddress());

            AggregateException aggregateException = Assert.ThrowsException <AggregateException>(() =>
            {
                AmlResult amlResult = client.PerformAmlCheck(amlProfile: amlProfile);
            });

            Assert.IsTrue(Exceptions.IsExceptionInAggregateException <JsonSerializationException>(aggregateException));
        }
コード例 #8
0
        public async Task PerformAmlCheckAsyncShouldReturnCorrectValues()
        {
            Mock <HttpMessageHandler> handlerMock = SetupMockMessageHandler(
                HttpStatusCode.OK,
                "{\"on_fraud_list\":true,\"on_pep_list\":false,\"on_watch_list\":false}");

            var engine = new YotiClientEngine(new HttpClient(handlerMock.Object));

            AmlProfile amlProfile = TestTools.Aml.CreateStandardAmlProfile();

            AmlResult amlResult = await engine.PerformAmlCheckAsync(
                SdkId, _keyPair,
                new Uri(Constants.Api.DefaultYotiApiUrl),
                amlProfile);

            Assert.IsNotNull(amlResult);
            Assert.IsTrue(amlResult.IsOnFraudList());
            Assert.IsFalse(amlResult.IsOnPepList());
            Assert.IsFalse(amlResult.IsOnWatchList());
        }