示例#1
0
        private async Task <ClaimsIdentity> GetClaimsIdentity(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                return(await Task.FromResult <ClaimsIdentity>(null));
            }

            var userStore = new Mock <IUserStore <ApplicationUser> >();

            var userManager = new FakeUserManager(userStore.Object);
            // get the user to verifty
            var userToVerify = await userManager.FindByEmailAsync(userName);

            if (userToVerify == null)
            {
                return(await Task.FromResult <ClaimsIdentity>(null));
            }

            var jwtFactory = new Mock <IJwtFactory>();

            jwtFactory.Setup(It => It.GenerateClaimsIdentity(userName, userToVerify.Id))
            .Returns(new ClaimsIdentity(new GenericIdentity(userName, "Token"), new[]
            {
                new Claim(Constants.Strings.JwtClaimIdentifiers.Id, userToVerify.Id),
                new Claim(Constants.Strings.JwtClaimIdentifiers.Role, Constants.Strings.JwtClaims.ApiAccess)
            })
                     );
            return(await Task.FromResult(jwtFactory.Object.GenerateClaimsIdentity(userName, userToVerify.Id)));
        }