Exemplo n.º 1
0
        public async Task <ActionResult> Callback(string code)
        {
            try
            {
                var responseConfig = await ApiClientConfig.GetClientReponse(code);

                var tokenCookie = new HttpCookie("TokenGiven", responseConfig.AccessToken);
                var tokentime   = new HttpCookie("TokenTime", DateTime.Now.ToString());

                _cookiesManager.AddCookie(tokenCookie, Response);
                _cookiesManager.AddCookie(tokentime, Response);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
Exemplo n.º 2
0
        public async Task CacheNewCaptchaValidateAsync()
        {
            string token = GoliathHelper.GenerateSecureRandomNumber();

            _cookieManager.AddCookie(
                key: CookieKeys.ValidateCaptchaCookie,      // Name of the key.
                value: GoliathHash.HashStringSHA256(token), // A hash derived from token.
                expireTime: DateTime.UtcNow.AddMinutes(5)   // Expires in 5 minutes.
                );
            // Add the generated random number to the database.
            await _validTokens.AddTokenAsync(key : token);
        }
        public async Task CreateTokenAsync(string userName, string token)
        {
            string userId = (await _repository.GetUserByNameAsync(userName)).Id;

            if (await _context.TwoFactorTokens.FirstOrDefaultAsync(u => u.UserId.Equals(userId)) != null)
            {
                // Destroy the old token.
                await DisposeTokenAsync(userId);
            }
            // Add a new authorize token.
            await _context.TwoFactorTokens.AddAsync(new TwoFactorAuthorizeToken()
            {
                UserId         = userId,
                AuthorizeToken = token
            });

            _cookies.AddCookie(CookieKeys.TwoFactorAuthorizeCookie, GoliathHash.HashStringSHA256(token), DateTime.UtcNow.AddMinutes(10));
            await _context.SaveChangesAsync();
        }