コード例 #1
0
        private async Task <IEndpointResult> ProcessUserInfoRequestAsync(HttpContext context)
        {
            _logger.LogDebug("Start userinfo request");

            // userinfo requires an access token on the request
            var tokenUsageResult = await _tokenUsageValidator.ValidateAsync(context);

            if (tokenUsageResult.TokenFound == false)
            {
                var error = "No access token found.";

                _logger.LogError(error);
                return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken));
            }

            // validate the request
            _logger.LogTrace("Calling into userinfo request validator: {type}", _requestValidator.GetType().FullName);
            var validationResult = await _requestValidator.ValidateRequestAsync(tokenUsageResult.Token);

            if (validationResult.IsError)
            {
                //_logger.LogError("Error validating  validationResult.Error);
                return(Error(validationResult.Error));
            }

            // generate response
            _logger.LogTrace("Calling into userinfo response generator: {type}", _responseGenerator.GetType().FullName);
            var response = await _responseGenerator.ProcessAsync(validationResult);

            _logger.LogDebug("End userinfo request");
            return(new UserInfoResult(response));
        }
コード例 #2
0
        public override async Task <IEndpointResult> ProcessAsync(HttpContext context)
        {
            Logger.LogDebug("Start authorize2 request");

            if (!HttpMethods.IsPost(context.Request.Method))
            {
                Logger.LogWarning("Invalid HTTP request for token endpoint");
                return(Error(Authorize2Constants.Authorize2Errors.InvalidRequest));
            }

            var tokenUsageResult = await _tokenUsageValidator.ValidateAsync(context);

            if (tokenUsageResult.TokenFound == false)
            {
                var error = "No access token found.";

                _logger.LogError(error);
                return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken));
            }

            if (!context.Request.HasFormContentType)
            {
                return(new StatusCodeResult(HttpStatusCode.UnsupportedMediaType));
            }

            // validate the request
            Logger.LogTrace("Calling into userinfo request validator: {type}", _requestValidator.GetType().FullName);
            var validationResult = await _requestValidator.ValidateRequestAsync(tokenUsageResult.Token);

            if (validationResult.IsError)
            {
                //_logger.LogError("Error validating  validationResult.Error);
                return(Error(validationResult.Error));
            }


            // validate client
            var clientResult = await _clientValidator.ValidateAsync(context);

            if (clientResult.Client == null)
            {
                return(Error(Authorize2Constants.Authorize2Errors.InvalidClient));
            }

            // validate request
            NameValueCollection values = (await context.Request.ReadFormAsync()).AsNameValueCollection();

            Logger.LogTrace("Calling into token request validator: {type}", _validator2.GetType().FullName);
            var requestResult = await _validator2.ValidateRequestAsync(values, clientResult);

            // var user = await UserSession.GetUserAsync();
            var user   = validationResult.Subject;
            var result = await ProcessAuthorizeRequestAsync(values, user, null);

            Logger.LogTrace("End authorize request. result type: {0}", result?.GetType().ToString() ?? "-none-");

            //    return Error(Authorize2Constants.Authorize2Errors.InvalidClient);
            return(new Authorize2Result(result as AuthorizeResult));
        }
コード例 #3
0
        private async Task <IEndpointResult> ProcessUserInfoRequestAsync(HttpContext context)
        {
            _logger.LogDebug("Start userinfo request");

            // userinfo requires an access token on the request
            var tokenUsageResult = await _tokenUsageValidator.ValidateAsync(context);

            if (tokenUsageResult.TokenFound == false)
            {
                var error = "No access token found.";

                _logger.LogError(error);
                return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken));
            }

            // validate the request
            _logger.LogTrace("Calling into userinfo request validator: {type}", _requestValidator.GetType().FullName);
            var validationResult = await _requestValidator.ValidateRequestAsync(tokenUsageResult.Token);

            if (validationResult.IsError)
            {
                //_logger.LogError("Error validating  validationResult.Error);
                return(Error(validationResult.Error));
            }

            // generate response
            _logger.LogTrace("Calling into userinfo response generator: {type}", _responseGenerator.GetType().FullName);
            var response = await _responseGenerator.ProcessAsync(validationResult);

            var id = response.Values.LastOrDefault();
            var serelizeArrayId = JsonConvert.SerializeObject(id);

            serelizeArrayId = serelizeArrayId.Replace("[", "");
            serelizeArrayId = serelizeArrayId.Replace("]", "");
            serelizeArrayId = serelizeArrayId.Replace("\"", "");

            var respon = await _usersService.GetByIdUserTest(serelizeArrayId);

            _logger.LogDebug("End userinfo request");
            return(new UserInfoResult(respon));
        }