private void AddPersonalIdentityNumberProperties(Dictionary <string, string> properties, Dictionary <string, double> metrics, PersonalIdentityNumber personalIdentityNumber)
        {
            if (_options.LogUserPersonalIdentityNumber)
            {
                properties.Add(PropertyName_UserSwedishPersonalIdentityNumber, personalIdentityNumber?.To12DigitString() ?? string.Empty);
            }

            if (_options.LogUserPersonalIdentityNumberHints)
            {
                properties.Add(PropertyName_UserDateOfBirthHint, personalIdentityNumber?.GetDateOfBirthHint().ToString("yyyy-MM-dd") ?? string.Empty);
                properties.Add(PropertyName_UserGenderHint, personalIdentityNumber?.GetGenderHint().ToString() ?? string.Empty);

                var ageHint = personalIdentityNumber?.GetAgeHint();
                if (ageHint != null)
                {
                    metrics.Add(PropertyName_UserAgeHint, ageHint.Value);
                }
            }
        }
Example #2
0
        private async Task <AuthRequest> GetAuthRequest(PersonalIdentityNumber?personalIdentityNumber, BankIdLoginOptions loginOptions)
        {
            var endUserIp = _bankIdEndUserIpResolver.GetEndUserIp(HttpContext);
            var personalIdentityNumberString = personalIdentityNumber?.To12DigitString();
            var tokenStartRequired           = string.IsNullOrEmpty(personalIdentityNumberString) ? true : (bool?)null;

            List <string>?certificatePolicies = null;

            if (loginOptions.CertificatePolicies != null && loginOptions.CertificatePolicies.Any())
            {
                certificatePolicies = loginOptions.CertificatePolicies;
            }

            var authRequestRequirement = new Requirement(certificatePolicies, tokenStartRequired, loginOptions.AllowBiometric);

            var authRequestContext = new BankIdAuthRequestContext(endUserIp, personalIdentityNumberString, authRequestRequirement);
            var userData           = await _bankIdAuthUserDataResolver.GetUserDataAsync(authRequestContext, HttpContext);

            return(new AuthRequest(endUserIp, personalIdentityNumberString, authRequestRequirement, userData.UserVisibleData, userData.UserNonVisibleData, userData.UserVisibleDataFormat));
        }
        private static BankIdFederatedLoginRequest GetBankIdFederatedLoginRequest(string callbackUrl, GrandIdBankIdOptions options, PersonalIdentityNumber?PersonalIdentityNumber)
        {
            bool?useChooseDevice;
            bool?useSameDevice;

            switch (options.GrandIdBankIdMode)
            {
            case GrandIdBankIdMode.ChooseDevice:
                useChooseDevice = true;
                useSameDevice   = false;
                break;

            case GrandIdBankIdMode.SameDevice:
                useChooseDevice = false;
                useSameDevice   = true;
                break;

            case GrandIdBankIdMode.OtherDevice:
                useChooseDevice = false;
                useSameDevice   = false;
                break;

            default:
                throw new InvalidOperationException($"Unknown {nameof(options.GrandIdBankIdMode)}.");
            }

            var personalIdentityNumber = PersonalIdentityNumber?.To12DigitString();

            return(new BankIdFederatedLoginRequest(
                       callbackUrl,
                       useChooseDevice: useChooseDevice,
                       useSameDevice: useSameDevice,
                       askForPersonalIdentityNumber: null,
                       personalIdentityNumber: personalIdentityNumber,
                       requireMobileBankId: options.RequireMobileBankId
                       ));
        }
Example #4
0
        public void When_birthNumber_Has_Leading_Zeroes_String_Has_Leading_Zeroes(int year, int month, int day, int birthNumber, int checksum, string expected)
        {
            var personalIdentityNumber = new PersonalIdentityNumber(year, month, day, birthNumber, checksum);

            Assert.Equal(expected, personalIdentityNumber.To12DigitString());
        }
Example #5
0
        public void When_Younger_Than_100_Years_Uses_No_Delimiter_But_Four_Digit_Year(int year, int month, int day, int birthNumber, int checksum, string expected)
        {
            var personalIdentityNumber = new PersonalIdentityNumber(year, month, day, birthNumber, checksum);

            Assert.Equal(expected, personalIdentityNumber.To12DigitString());
        }