예제 #1
0
        public void Post_With_Invalid_Grant_Type_Should_Return_404()
        {
            A.CallTo(() => _tokenEndpointService.ValidateRequest(A <TokenRequest> .That.Matches(x =>
                                                                                                x.GrantType == "bad_grant"), A <NancyContext> .Ignored))
            .Returns(ErrorType.InvalidGrant);

            var response = _browser.Post("/oauth/token", with =>
            {
                with.HttpRequest();
                with.FormValue("grant_type", "bad_grant");
            });

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
예제 #2
0
        public void ValidateRequest_ShouldThrow_NotImplementedException()
        {
            var request = new TokenRequest();
            var context = new NancyContext();

            Assert.Throws <NotImplementedException>(() => _service.ValidateRequest(request, context));
        }
예제 #3
0
        private dynamic CreateToken()
        {
            var request = this.Bind <TokenRequest>();

            var result = _service.ValidateRequest(request, Context);

            if (!result.IsValid)
            {
                return(Response.AsErrorResponse(BuildErrorResponse(result.ErrorType), request.RedirectUri));
            }

            var response = _service.CreateTokenResponse(request, Context);

            return(Response.AsJson(response));
        }