コード例 #1
0
        public static IEnumerable <Claim> GetAllClaims(this UserAccount account)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }

            var claims = new List <Claim>();

            claims.AddRange(account.GetIdentificationClaims());

            if (!String.IsNullOrWhiteSpace(account.Email))
            {
                claims.Add(new Claim(ClaimTypes.Email, account.Email));
            }
            if (!String.IsNullOrWhiteSpace(account.MobilePhoneNumber))
            {
                claims.Add(new Claim(ClaimTypes.MobilePhone, account.MobilePhoneNumber));
            }

            var x509 = from c in account.Certificates
                       select new Claim(ClaimTypes.X500DistinguishedName, c.Subject);

            claims.AddRange(x509);

            var otherClaims =
                (from uc in account.Claims
                 select new Claim(uc.Type, uc.Value)).ToList();

            claims.AddRange(otherClaims);

            return(claims);
        }
コード例 #2
0
        private static List <Claim> GetBasicClaims(UserAccount account, string method)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }

            var claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.AuthenticationMethod, method));
            claims.Add(new Claim(ClaimTypes.AuthenticationInstant, DateTime.UtcNow.ToString("s")));
            claims.AddRange(account.GetIdentificationClaims());

            return(claims);
        }