コード例 #1
0
ファイル: JwtService.cs プロジェクト: ChrisSure/Phone911
        /// <summary>
        /// Method set user claims
        /// <summary>
        /// <param name="userInfo"><see cref="ApplicationUser"/></param>
        /// <returns>Claim[]</returns>
        public async Task <Claim[]> GetClaimsAsync(ApplicationUser userInfo)
        {
            var roles = await userService.GetUserRolesAsync(userInfo);

            var profileName = (await profileService.GetProfileByUserId(userInfo.Id)).Name;

            var claims = new List <Claim> {
                new Claim(JwtRegisteredClaimNames.Sub, profileName),
                new Claim(JwtRegisteredClaimNames.Email, userInfo.Email),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim("uid", userInfo.Id)
            };

            claims.Add(new Claim(ClaimTypes.Role, roles[0]));

            return(claims.ToArray());
        }