예제 #1
0
 protected TwoFactorResponse CreateViewModel(TwoFactorSetupResponse entity)
 {
     return(new TwoFactorResponse
     {
         AccountSecretKey = entity.AccountSecretKey,
         ManualEntryKey = entity.ManualEntryKey
     });
 }
예제 #2
0
        private TwoFactorSetupResponse GenerateSetupCode(string issuer, string accountTitleNoSpaces, string accountSecretKey, int qrCodeWidth, int qrCodeHeight, bool useHttps)
        {
            if (accountTitleNoSpaces == null)
            {
                throw new NullReferenceException("Account Title is null");
            }

            accountTitleNoSpaces = accountTitleNoSpaces.Replace(" ", "");

            var twoFactorSetup = new TwoFactorSetupResponse
            {
                Account          = accountTitleNoSpaces,
                AccountSecretKey = accountSecretKey
            };

            var encodedSecretKey = EncodeAccountSecretKey(accountSecretKey);

            twoFactorSetup.ManualEntryKey = encodedSecretKey;

            string provisionUrl;

            if (string.IsNullOrEmpty(issuer))
            {
                provisionUrl = UrlEncode(String.Format("otpauth://totp/{0}?secret={1}", accountTitleNoSpaces, encodedSecretKey));
            }
            else
            {
                provisionUrl = UrlEncode(String.Format("otpauth://totp/{0}?secret={1}&issuer={2}", accountTitleNoSpaces, encodedSecretKey, UrlEncode(issuer)));
            }

            var protocol = useHttps ? "https" : "http";
            var url      =
                $"{protocol}://chart.googleapis.com/chart?cht=qr&chs={qrCodeWidth}x{qrCodeHeight}&chl={provisionUrl}";

            twoFactorSetup.QrCodeSetupImageUrl = url;

            return(twoFactorSetup);
        }