public async Task When_Passing_Null_Parameter_To_PostIntrospection_Then_Exception_Is_Thrown()
        {
            // ARRANGE
            InitializeFakeObjects();

            // ACT & ASSERT
            await Assert.ThrowsAsync <ArgumentNullException>(() => _introspectionActions.PostIntrospection(null, null));
        }
Beispiel #2
0
        public async Task <Introspection> Post()
        {
            if (Request.Form == null)
            {
                throw new ArgumentNullException(nameof(Request.Form));
            }

            var          serializer           = new ParamSerializer();
            var          introspectionRequest = serializer.Deserialize <IntrospectionRequest>(Request.Form);
            StringValues authorizationHeader;
            AuthenticationHeaderValue authenticationHeaderValue = null;

            if (Request.Headers.TryGetValue("Authorization", out authorizationHeader))
            {
                var authorizationHeaderValue         = authorizationHeader.First();
                var splittedAuthorizationHeaderValue = authorizationHeaderValue.Split(' ');
                if (splittedAuthorizationHeaderValue.Count() == 2)
                {
                    authenticationHeaderValue = new AuthenticationHeaderValue(
                        splittedAuthorizationHeaderValue[0],
                        splittedAuthorizationHeaderValue[1]);
                }
            }

            var result = await _introspectionActions.PostIntrospection(introspectionRequest.ToParameter(), authenticationHeaderValue);

            return(result.ToDto());
        }
        public async Task <IActionResult> Post()
        {
            try
            {
                if (Request.Form == null)
                {
                    return(BuildError(ErrorCodes.InvalidRequestCode, "no parameter in body request", HttpStatusCode.BadRequest));
                }
            }
            catch (Exception)
            {
                return(BuildError(ErrorCodes.InvalidRequestCode, "no parameter in body request", HttpStatusCode.BadRequest));
            }

            var nameValueCollection = new NameValueCollection();

            foreach (var kvp in Request.Form)
            {
                nameValueCollection.Add(kvp.Key, kvp.Value);
            }

            var          s                    = Thread.CurrentThread.ManagedThreadId;
            var          serializer           = new ParamSerializer();
            var          introspectionRequest = serializer.Deserialize <IntrospectionRequest>(nameValueCollection);
            StringValues authorizationHeader;
            AuthenticationHeaderValue authenticationHeaderValue = null;

            if (Request.Headers.TryGetValue("Authorization", out authorizationHeader))
            {
                var authorizationHeaderValue         = authorizationHeader.First();
                var splittedAuthorizationHeaderValue = authorizationHeaderValue.Split(' ');
                if (splittedAuthorizationHeaderValue.Count() == 2)
                {
                    authenticationHeaderValue = new AuthenticationHeaderValue(
                        splittedAuthorizationHeaderValue[0],
                        splittedAuthorizationHeaderValue[1]);
                }
            }

            var issuerName = Request.GetAbsoluteUriWithVirtualPath();
            var result     = await _introspectionActions.PostIntrospection(introspectionRequest.ToParameter(), authenticationHeaderValue, issuerName);

            return(new OkObjectResult(result.ToDto()));
        }
Beispiel #4
0
        public async Task <Introspection> Post()
        {
            if (Request.Form == null)
            {
                throw new ArgumentNullException(nameof(Request.Form));
            }

            var nameValueCollection = new NameValueCollection();

            foreach (var kvp in Request.Form)
            {
                nameValueCollection.Add(kvp.Key, kvp.Value);
            }

            var          s                    = Thread.CurrentThread.ManagedThreadId;
            var          serializer           = new ParamSerializer();
            var          introspectionRequest = serializer.Deserialize <IntrospectionRequest>(nameValueCollection);
            StringValues authorizationHeader;
            AuthenticationHeaderValue authenticationHeaderValue = null;

            if (Request.Headers.TryGetValue("Authorization", out authorizationHeader))
            {
                var authorizationHeaderValue         = authorizationHeader.First();
                var splittedAuthorizationHeaderValue = authorizationHeaderValue.Split(' ');
                if (splittedAuthorizationHeaderValue.Count() == 2)
                {
                    authenticationHeaderValue = new AuthenticationHeaderValue(
                        splittedAuthorizationHeaderValue[0],
                        splittedAuthorizationHeaderValue[1]);
                }
            }

            var result = await _introspectionActions.PostIntrospection(introspectionRequest.ToParameter(), authenticationHeaderValue);

            return(result.ToDto());
        }