Ejemplo n.º 1
0
        /// <summary>
        /// 创建身份验证票据
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="isPresistent">是否持久化</param>
        protected virtual void OnCreateAuthenticationTicket(string userName, bool isPresistent)
        {
            var user = UserManager.Instance.GetUserInfo(userName);
            if (user == null)
                throw new InvalidOperationException("Can not find the user, the user is null.");

            var userData = new AuthenticationData(user.ID, user.UserName, user.Email);
            this.AuthenticationTicket = new OwinAuthenticationTicket(isPresistent, userData, authenticationType);
        }
        /// <summary>
        /// 初始化一个新的<c>OwinAuthenticationTicket</c>实例
        /// </summary>
        /// <param name="isPresistent">是否持久化验证会话</param>
        /// <param name="data">要存储的数据</param>
        /// <param name="authenticationType">验证类型</param>
        public OwinAuthenticationTicket(bool isPresistent, AuthenticationData data, string authenticationType)
        {
            this.Properties = new AuthenticationProperties
            {
                IsPersistent = isPresistent
            };

            var claimManager = new ClaimManager(data);
            var identity = new ClaimsIdentity(claimManager.Claims, authenticationType);
            this.Identities = new[] { identity };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 初始化一个新的<c>ClaimManager</c>实例
        /// </summary>
        /// <param name="data">身份验证数据</param>
        public ClaimManager(AuthenticationData data)
        {
            this._claims.Add(new Claim(ClaimTypes.NameIdentifier, data.Identifer.ToString()));
            this._claims.Add(new Claim(ClaimTypes.Name, data.Name));

            if (!String.IsNullOrWhiteSpace(data.Email))
                this._claims.Add(new Claim(ClaimTypes.Email, data.Email));

            if (data.Roles != null)
            {
                foreach (var role in data.Roles)
                    this._claims.Add(new Claim(ClaimTypes.Role, role));
            }
        }