示例#1
0
        public void GetToken()
        {
            var server1 = new ServerWithAuthorizationCode("test", "testsecret",
                                                          new Uri("http://example.org/foo"),
                                                          new Uri("http://example.org/access"),
                                                          new Uri("http://example.org/test2"));
            var resourceOwner1 = new ResourceOwner("testmann1");

            Tokens.CleanUpForTests();
            var token1 = Tokens.GetToken(server1, resourceOwner1);

            token1.Should().NotBeNull();
            token1.ResourceOwner.Should().Be(resourceOwner1);
            token1.Server.Should().Be(server1);
            token1.AuthorizationCode.Should().BeNullOrEmpty();
            token1.AccessToken.Should().BeNullOrEmpty();
            token1.RefreshToken.Should().BeNullOrEmpty();

            token1.AuthorizationCode = "AuthorizationCode";
            token1.AccessToken       = "AccessToken";
            token1.RefreshToken      = "RefreshToken";
            token1.Expires           = DateTime.Now;

            var token2 = Tokens.GetToken(server1, resourceOwner1);

            token2.AuthorizationCode.Should().Be("AuthorizationCode");
            token2.AccessToken.Should().Be("AccessToken");
            token2.RefreshToken.Should().Be("RefreshToken");
            DateTime.Now.Subtract(token2.Expires).Should().BeLessOrEqualTo(new TimeSpan(0, 0, 1, 0));
        }
示例#2
0
        public void DisposeAndLoad()
        {
            Tokens.CleanUpForTests();
            var server1 = ServersWithAuthorizationCode.Add("testclient", "testsecret",
                                                           new Uri("http://example.com/uri1"),
                                                           new Uri("http://example.org/access"),
                                                           new Uri("http://example.com/uri2"));
            var resourceOwner1 = ResourceOwners.Add("testuser");

            Token token = Tokens.GetToken(server1, resourceOwner1);

            token.Expires           = DateTime.Now;
            token.AccessToken       = "token1";
            token.AuthorizationCode = "token2";
            token.RefreshToken      = "token3";

            Tokens.SaveToIsoStore();
            Tokens.LoadFromIsoStore();

            var tokenAfter = Tokens.GetToken(server1, resourceOwner1);

            tokenAfter.Should().NotBeNull();
            tokenAfter.Expires.ToString().Should().Be(token.Expires.ToString());
            tokenAfter.AccessToken.Should().Be(token.AccessToken);
            tokenAfter.AuthorizationCode.Should().Be(token.AuthorizationCode);
            tokenAfter.RefreshToken.Should().Be(token.RefreshToken);
        }
        public void SetUp()
        {
            Tokens.CleanUpForTests();
            ResourceOwners.CleanUpForTests();
            ServersWithAuthorizationCode.CleanUpForTests();

            var authorizationRequestUri = new Uri("http://example.org/GetAccessAndRefreshTokenTest/Authorization");
            var accessTokenUri          = new Uri("http://example.org/GetAccessAndRefreshTokenTest/Access");
            var redirectionUri          = new Uri("http://example.org/GetAccessAndRefreshTokenTest/redirectionUri");

            _server                  = ServersWithAuthorizationCode.Add("123456789", "testsecret", authorizationRequestUri, accessTokenUri, redirectionUri);
            _resourceOwner           = ResourceOwners.Add("Test");
            _token                   = Tokens.GetToken(_server, _resourceOwner);
            _token.RedirectUri       = _server.RedirectionUri;
            _token.AuthorizationCode = "Aplx10BeZQQYbYS6WxSbIA";
        }
 public void SetUp()
 {
     ResourceOwners.CleanUpForTests();
     ServersWithAuthorizationCode.CleanUpForTests();
     Tokens.CleanUpForTests();
 }