Ejemplo n.º 1
0
        public void CreateTokenResponse_ShouldThrow_NotImplementedException()
        {
            var request = new TokenRequest();
            var context = new NancyContext();

            Assert.Throws <NotImplementedException>(() => _service.CreateTokenResponse(request, context));
        }
Ejemplo n.º 2
0
        public void Post_With_Valid_Grant_Should_Return_TokenResponse()
        {
            var tokenResponse = new TokenResponse
            {
                AccessToken  = "123",
                RefreshToken = "abc",
                ExpiresIn    = 86400,
                Scope        = "test",
                TokenType    = "bearer"
            };

            A.CallTo(() => _tokenEndpointService.CreateTokenResponse(A <TokenRequest> .Ignored, A <NancyContext> .Ignored))
            .Returns(tokenResponse);

            var response = _browser.Post("/oauth/token", with =>
            {
                with.HttpRequest();
                with.FormValue("grant_type", GrantTypes.Password);
            });
            var body = response.Body.DeserializeJson <TokenResponse>();

            Assert.IsNotNull(body);
            Assert.AreEqual("123", body.AccessToken);
            Assert.AreEqual("abc", body.RefreshToken);
            Assert.AreEqual(86400, body.ExpiresIn);
            Assert.AreEqual("test", body.Scope);
            Assert.AreEqual("bearer", body.TokenType);
        }
Ejemplo n.º 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));
        }