示例#1
0
        public IActionResult VerifyAzureAdCode(TokenInput tokenInput)
        {
            if (string.IsNullOrWhiteSpace(tokenInput.Token))
            {
                _logger.LogInformation("Token is empty.");
                return(BadRequest());
            }

            var user = _authHandler.VerifyOauthForRegister(tokenInput.Token);

            if (user == null)
            {
                _logger.LogInformation("Auth handler rejected oauth token.");
                return(BadRequest());
            }

            if (_memoryCache.TryGetValue("R1" + user.Email, out string stringUuid))
            {
                _memoryCache.Remove("R1" + stringUuid);
            }

            var registerGuid      = SecureGuid.CreateSecureRfc4122Guid();
            var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5));

            _memoryCache.Set("R1" + registerGuid, user, cacheEntryOptions);
            _memoryCache.Set("R1" + user.Email, registerGuid.ToString(), cacheEntryOptions);

            var response = new OauthSuccessResponse
            {
                Name         = user.Name,
                Email        = user.Email,
                RegisterCode = registerGuid.ToString()
            };

            return(Ok(response));
        }