コード例 #1
0
ファイル: AuthSession.cs プロジェクト: eznew-net/EZNEW.Web
        /// <summary>
        /// Get auth session by authentication ticket
        /// </summary>
        /// <param name="ticket">Ticket</param>
        /// <returns>Return auth session</returns>
        public static AuthSession FromAuthenticationTicket(AuthenticationTicket ticket)
        {
            if (ticket == null)
            {
                return(null);
            }
            var session = new AuthSession()
            {
                AuthenticationScheme = ticket.AuthenticationScheme,
                PropertiesItems      = ticket.Properties.Items.ToDictionary(c => c.Key, c => c.Value),
                Claims = ticket.Principal.Claims?.ToDictionary(c => c.Type, c => c.Value),
            };
            var sessionConfig = SessionConfiguration.GetSessionConfiguration();

            if (session.Claims?.ContainsKey(sessionConfig.SessionClaimName) ?? false)
            {
                session.SessionToken = session.Claims[sessionConfig.SessionClaimName];
            }
            session.Expires = DateTimeOffset.Now.Add(sessionConfig.Expires);
            return(session);
        }