Пример #1
0
        // GET: Account/Connect?token
        public ActionResult Connect(string token)
        {
            try
            {
                string sdkId            = ConfigurationManager.AppSettings["Yoti.SdkId"];
                var    privateKeyStream = System.IO.File.OpenText(Server.MapPath("~/application-key.pem"));
                var    yotiClient       = new YotiClient(sdkId, privateKeyStream);

                var activityDetails = yotiClient.GetActivityDetails(token);
                if (activityDetails.Outcome == ActivityOutcome.Success)
                {
                    var yotiProfile = activityDetails.UserProfile;

                    User user = UserManager.GetUserByYotiId(yotiProfile.Id);

                    // create new user if none exists
                    if (user == null)
                    {
                        user = new User
                        {
                            YotiId = yotiProfile.Id
                        };
                    }

                    // update user information
                    if (yotiProfile.Selfie != null)
                    {
                        user.Photo = yotiProfile.Selfie.Data;
                    }

                    if (!string.IsNullOrEmpty(yotiProfile.MobileNumber))
                    {
                        user.PhoneNumber = yotiProfile.MobileNumber;
                    }

                    UserManager.SaveUser(user);

                    var identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, user.Id.ToString()),
                    },
                                                      "ApplicationCookie");

                    var ctx         = Request.GetOwinContext();
                    var authManager = ctx.Authentication;

                    authManager.SignIn(identity);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("LoginFailure"));
                }
            } catch (Exception e)
            {
                ViewBag.Error = e.ToString();
                return(View());
            }
        }
        public void YotiClient_GetActivityDetails()
        {
            YotiClient client = CreateYotiClient();

            ActivityDetails activityDetails = client.GetActivityDetails(encryptedToken);

            Assert.IsNotNull(activityDetails.Outcome);
        }
Пример #3
0
        // GET: Account/Connect?token
        public ActionResult Connect(string token)
        {
            if (token == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            try
            {
                string sdkId = Environment.GetEnvironmentVariable("YOTI_CLIENT_SDK_ID");
                _logger.LogInformation(string.Format("sdkId='{0}'", sdkId));

                string yotiKeyFilePath = Environment.GetEnvironmentVariable("YOTI_KEY_FILE_PATH");
                _logger.LogInformation(
                    string.Format(
                        "yotiKeyFilePath='{0}'",
                        yotiKeyFilePath));

                StreamReader privateKeyStream = System.IO.File.OpenText(yotiKeyFilePath);

                var yotiClient = new YotiClient(sdkId, privateKeyStream);

                ActivityDetails activityDetails = yotiClient.GetActivityDetails(token);

                var profile = activityDetails.Profile;

                ViewBag.RememberMeID = activityDetails.RememberMeId;

                DisplayAttributes displayAttributes = CreateDisplayAttributes(profile.AttributeCollection);

                if (profile.FullName != null)
                {
                    displayAttributes.FullName = profile.FullName.GetValue();
                }

                YotiAttribute <Image> selfie = profile.Selfie;
                if (profile.Selfie != null)
                {
                    displayAttributes.Base64Selfie = selfie.GetValue().GetBase64URI();
                }

                return(View(displayAttributes));
            }
            catch (Exception e)
            {
                _logger.LogError(
                    exception: e,
                    message: e.Message);

                TempData["Error"]          = e.Message;
                TempData["InnerException"] = e.InnerException?.Message;
                return(RedirectToAction("Error"));
            }
        }
        // GET: Account/Connect?token
        public ActionResult Connect(string token)
        {
            try
            {
                ViewBag.YotiAppId = _appId;
                string sdkId = Environment.GetEnvironmentVariable("YOTI_CLIENT_SDK_ID");
                _logger.LogInformation(string.Format("sdkId='{0}'", sdkId));

                var yotiKeyFilePath = Environment.GetEnvironmentVariable("YOTI_KEY_FILE_PATH");
                _logger.LogInformation(
                    string.Format(
                        "yotiKeyFilePath='{0}'",
                        yotiKeyFilePath));

                var privateKeyStream = System.IO.File.OpenText(yotiKeyFilePath);

                var yotiClient = new YotiClient(sdkId, privateKeyStream);

                var activityDetails = yotiClient.GetActivityDetails(token);
                if (activityDetails.Outcome == ActivityOutcome.Success)
                {
                    _logger.LogInformation("ActivityOutcome=Success");

                    var yotiProfile = activityDetails.Profile;

                    if (yotiProfile.Selfie != null)
                    {
                        PhotoBytes = yotiProfile.Selfie.GetImage().Data;
                    }

                    return(View(yotiProfile));
                }
                else
                {
                    _logger.LogWarning(
                        string.Format(
                            "ActivityOutcome='{0}'",
                            activityDetails.Outcome));
                    return(RedirectToAction("LoginFailure", "Home"));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(
                    exception: e,
                    message: "An error occurred");

                return(RedirectToAction("LoginFailure", "Home"));
            }
        }
Пример #5
0
        // GET: Account/Connect?token
        public ActionResult Connect(string token)
        {
            if (token == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            try
            {
                string sdkId            = ConfigurationManager.AppSettings["YOTI_CLIENT_SDK_ID"];
                var    privateKeyStream = System.IO.File.OpenText(ConfigurationManager.AppSettings["YOTI_KEY_FILE_PATH"]);
                var    yotiClient       = new YotiClient(sdkId, privateKeyStream);

                var activityDetails = yotiClient.GetActivityDetails(token);
                if (activityDetails.Outcome == ActivityOutcome.Success)
                {
                    var profile = activityDetails.Profile;

                    User user = UserManager.GetUserByYotiId(profile.Id);

                    if (user == null)
                    {
                        user = new User
                        {
                            YotiId = profile.Id
                        };
                    }

                    if (profile.Selfie != null)
                    {
                        user.Base64Photo = profile.Selfie.GetBase64URI();
                        user.Photo       = profile.Selfie.GetImage().Data;
                        PhotoBytes       = user.Photo;
                    }
                    else
                    {
                        ViewBag.Message = "No photo provided, change the application settings to request a photo from the user for this demo";
                    }

                    UpdateAttributesIfPresent(profile, user);

                    UserManager.SaveUser(user);

                    var identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, user.Id.ToString()),
                    },
                                                      "ApplicationCookie");

                    var ctx         = Request.GetOwinContext();
                    var authManager = ctx.Authentication;

                    authManager.SignIn(identity);

                    return(View(user));
                }
                else
                {
                    return(RedirectToAction("LoginFailure", "Home"));
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = e.ToString();
                return(RedirectToAction("LoginFailure", "Home"));
            }
        }
Пример #6
0
        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());
        }