コード例 #1
0
        /// <summary>
        /// Vérifie que le token est valide
        /// </summary>
        /// <param name="input"> Final token </param>
        /// <param name="stoken"> Input token </param>
        /// <returns></returns>
        private bool IsValidToken(string input, SecurityToken stoken)
        {
            //
            Token token = _context.Token.Single(tken => tken.Token1.Equals(input));

            //
            if (token.Exp != null)
            {
                if (DateTime.Now > token.Exp)
                {
                    // If expired, removal + invalid
                    _context.Token.Remove(token);
                    _context.SaveChanges();
                    return(false);
                }
                else
                {
                    var tokenValidationParameters = new TokenValidationParameters()
                    {
                        ValidAudiences   = CompanyInfoUtil.CompanyClaims.ValidAudiences,
                        ValidIssuers     = CompanyInfoUtil.CompanyClaims.ValidIssuers,
                        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(token.Jni))
                    };

                    string        realToken = input.Substring(0, input.Length - 12);
                    SecurityToken Validated;

                    // Generate a new token plus comparing both
                    TokenHandler.ValidateToken(realToken, tokenValidationParameters, out Validated);

                    return(token.Boundmac.Equals(Validated.ToString()));
                }
            }
            else
            {
                return(true);
            }
        }