Example #1
0
        /// <summary>
        /// Invalidates the token, by changing its validuntil date to "now"
        /// </summary>
        /// <param name="token">The login token that is to be invalidated</param>
        /// <returns>The new/invalidated tokendata</returns>
        public static Common.DTO.TokenData Logout(Monosoft.Common.DTO.Token token, Guid organisationContext)
        {
            var oldtoken = DataContext.Instance.Tokens.Where(p => p.Id == token.Tokenid).FirstOrDefault();

            oldtoken.ValidUntil = DateTime.Now;
            DataContext.Instance.SaveChanges();
            return(oldtoken.ConvertToTokenData(token.Scope, oldtoken.User, organisationContext));
        }
Example #2
0
        /// <summary>
        /// Returns tokendata for a given token (invalid token without claims if data is not found)
        /// </summary>
        /// <param name="token">The token to verify</param>
        /// <returns>Tokendata</returns>
        public static Monosoft.Common.DTO.TokenData Verify(Monosoft.Common.DTO.Token token, Guid organisationContext)
        {
            Token t = DataContext.Instance.Tokens.Where(p => p.Id == token.Tokenid).FirstOrDefault();

            if (t != null)
            {
                var user = DataContext.Instance.Users.Where(p => p.Id == t.User.Id).FirstOrDefault();
                if (user != null)
                {
                    return(t.ConvertToTokenData(token.Scope, user, organisationContext));
                }
            }

            return(new Monosoft.Common.DTO.TokenData()
            {
                Claims = null, Tokenid = Guid.Empty, ValidUntil = DateTime.Now
            });
        }