public async Task <Token> UpdateTokens(string realmId, string newAccessToken, string newRefreshToken)
        {
            Token token = await _tokens.Token.FirstOrDefaultAsync(t => t.RealmId == realmId);

            if (token != null)
            {
                token.AccessToken  = newAccessToken;
                token.RefreshToken = newRefreshToken;
            }
            _tokens.SaveChanges();
            return(token);
        }
예제 #2
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);
            }
        }
        public Guid Post(string tenantId, string url, string groupId, string mail)
        {
            var GUID  = Guid.NewGuid();
            var token = new Token {
                GUID = GUID, TenantId = tenantId, Url = url, GroupId = groupId, Mail = mail
            };

            db.Add(token);
            try
            {
                db.SaveChanges();
                return(GUID);
            }
            catch (Exception ex)
            {
                throw new Exception("Error in save data to database" + ex.Message);
            }
        }
        public async Task <IActionResult> PostStats([FromBody] Stats stats)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Stats.Add(stats);
            try
            {
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(CreatedAtAction("GetStats", new { id = stats.StatsId }, stats));
        }