コード例 #1
0
        public void ValidateUserNameAndPasswordPassingTest()
        {
            var users = IdentityServerDBHelper.ValidateUserNameAndPassword(ConnectionConst.CORRECTCONNECTIONSTRING,
                                                                           "PersonalMovieDBUI", "PersonalMovieDBUI00..").Result;

            Assert.NotNull(users);
        }
コード例 #2
0
        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            try {
                var usersFromDB = await IdentityServerDBHelper.ValidateUserNameAndPassword(
                    Startup.Configuration.GetSection("ConnectionString").Value,
                    context.UserName, context.Password);

                if (usersFromDB != null && usersFromDB.Count != 0)
                {
                    context.Result = new GrantValidationResult(
                        usersFromDB[0].userSubject,
                        authenticationMethod: "password");
                }
                else
                {
                    context.Result = new GrantValidationResult(
                        TokenRequestErrors.InvalidGrant,
                        "Invalid User Credential");
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message.ToString());
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant,
                    "Invalid User Credential");
            }
        }