コード例 #1
0
        private IAuthorizationContext MakeAuthorizatonCodeContext(string responseType)
        {
            AuthorizationContext context = new AuthorizationContext
            {
                AuthorizationGrant = new AuthorizationGrantBase
                {
                    //Scope = new string[] { "create", "delete" },
                    Code = "special-token-value"
                },
                Token = new AccessTokenBase
                {
                    Token = "access-token",
                    TokenType="bearer",
                    ExpiresIn = 123,
                    Scope = new string[]{ "read"}
                },
                IsApproved = true,
                RedirectUri = new Uri("http://www.mysite.com/callback?param=maintain"),
                ResourceOwnerUsername = "******",
                ResponseType = responseType,
                Scope = new string[] { "create", "delete" },
                State = "special"
            };

            return context;
        }
コード例 #2
0
 private static IAuthorizationContext MakeAuthorizationContext()
 {
     IAuthorizationContext context = new AuthorizationContext();
     context.Client = new ClientBase { ClientId = "12345", ClientSecret = "secret" };
     context.RedirectUri = new Uri("http://www.mysite.com", UriKind.RelativeOrAbsolute);
     context.ResponseType = Parameters.ResponseTypeValues.AuthorizationCode;
     context.Scope = new string[] { "create-customer", "view-clients" };
     context.State = "my state";
     return context;
 }
コード例 #3
0
        public void TestProcessorSatisfiedBy()
        {
            AuthorizationContext context = new AuthorizationContext();

            context.ResponseType = Parameters.ResponseTypeValues.AccessToken;

            ImplicitFlowProcessor processor = new ImplicitFlowProcessor(new Mock<IServiceFactory> ().Object);
            Assert.IsTrue(processor.IsSatisfiedBy(context));
            context.ResponseType = Parameters.ResponseTypeValues.AuthorizationCode;
            Assert.IsFalse(processor.IsSatisfiedBy(context));
        }
コード例 #4
0
        public void TestProcessTokenRequest()
        {
            AccessTokenBase token = new AccessTokenBase
            {
                Scope = new string[] { "create", "delete" },
                ExpiresIn = 120,
                RefreshToken = "refresh",
                Token = "token",
                TokenType = "bearer"
            };
            ClientBase client = new ClientBase
            {
                ClientId = "123",
                ClientSecret = "secret"
            };

			IAuthorizationGrant grant = new AuthorizationGrantBase
            {
                Code = "123"
            };

            AuthorizationContext context = new AuthorizationContext
            {
                Client = new ClientBase { ClientId = "123" },
                IsApproved = true,
                RedirectUri = new Uri("http://www.mysite.com/callback"),
                Scope = new string[] { "create", "delete" },
                ResourceOwnerUsername = "******"
            };

            Mock<IClientService> mckClientService = new Mock<IClientService>();
            mckClientService.Setup(x => x.FindClient("123")).Returns(client);

            Mock<IAuthorizationGrantService> mckGrantService = new Mock<IAuthorizationGrantService>();
            mckGrantService.Setup(x => x.IssueAuthorizationGrant(context)).Returns(grant);

            Mock<ITokenService> mckTokenService = new Mock<ITokenService>();
            mckTokenService.Setup(x => x.IssueAccessToken(grant)).Returns(token);

            Mock<IServiceFactory> mckFactory = new Mock<IServiceFactory>();
            mckFactory.SetupGet(x => x.TokenService).Returns(mckTokenService.Object);
            mckFactory.SetupGet(x => x.ClientService).Returns(mckClientService.Object);
            mckFactory.SetupGet(x => x.AuthorizationGrantService).Returns(mckGrantService.Object);

            ImplicitFlowProcessor processor = new ImplicitFlowProcessor(mckFactory.Object);
            processor.Process(context);

            Assert.AreEqual(token, context.Token);
            mckClientService.VerifyAll();
            mckFactory.VerifyAll();
            mckTokenService.VerifyAll();            
        }
コード例 #5
0
 private IAuthorizationContext MakeErrorAuthorizationContext(string responseType)
 {
     AuthorizationContext ctx = new AuthorizationContext
     {
         ResponseType = responseType,
         Error = new ErrorResponse
         {
             Error = Parameters.ErrorParameters.ErrorValues.AccessDenied,
             ErrorDescription = "You do not have access"
         },
         RedirectUri = new Uri("http://www.mysite.com/callback?param=maintain")
     };
     return ctx;
 }