Ejemplo n.º 1
0
        public async Task Login_ReturnsOKRequest_WhenModelIsValid()
        {
            var user = new UserForLoginDto
            {
                UserName = "******",
                Password = "******",
                MfaCode  = ""
            };

            var tfa = new TwoFactorAuthNet.TwoFactorAuth();

            user.MfaCode = tfa.GetCode(Base32.Encode(Encoding.UTF8.GetBytes(user.UserName)));


            var myContent   = JsonConvert.SerializeObject(user);
            var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpResponse = await _client.PostAsync("/api/auth/login", byteContent);

            // Must be successful.
            httpResponse.EnsureSuccessStatusCode();

            // Deserialize and examine results.
            var stringResponse = await httpResponse.Content.ReadAsStringAsync();

            var responseContent = JsonConvert.DeserializeObject <LoginWrapper>(stringResponse);

            Assert.IsType <UserForListDto>(responseContent.user);
        }
Ejemplo n.º 2
0
        private bool VerifyMFACode(string userName, string mfaCode)
        {
            var tfa = new TwoFactorAuthNet.TwoFactorAuth();

            return(tfa.VerifyCode(Base32.Encode(Encoding.UTF8.GetBytes(userName)), mfaCode));
        }