コード例 #1
0
        public void WhenAccessTokenIsValid_ThenReturnTrue()
        {
            var mocker = new AutoMoqer();

            mocker.MockServiceLocator();

            var issuer = new OAuthIssuer();

            mocker.GetMock <IOAuthServiceLocator>().Setup(x => x.Issuer).Returns(issuer);
            mocker.GetMock <IConfiguration>().Setup(x => x.AccessTokenExpirationLength).Returns(3600);
            var validator = mocker.Resolve <ResourceRequestAuthorizer>();

            var token =
                issuer.GenerateAccessToken(new TokenData
            {
                ConsumerId      = 1,
                ResourceOwnerId = 5,
                Timestamp       = DateTimeOffset.UtcNow.AddMinutes(-5).Ticks
            });


            mocker.GetMock <IOAuthRequest>().Setup(x => x.AccessToken).Returns(token);

            var result = validator.Authorize(mocker.GetMock <IOAuthRequest>().Object);

            Assert.IsTrue(result);
        }
コード例 #2
0
        public void GenerateAccessToken_GeneratesToken()
        {
            var ticks = DateTime.Now.Ticks;
            var data  = new TokenData {
                ConsumerId = 1, ResourceOwnerId = 2, Timestamp = ticks
            };
            var issuer = new OAuthIssuer();

            var token1 = issuer.GenerateAccessToken(data);
            var token2 = issuer.GenerateAccessToken(data);

            data.Timestamp = DateTime.Now.Ticks + 150;
            var token3 = issuer.GenerateAccessToken(data);

            Assert.AreEqual(token1, token2);
            Assert.AreNotEqual(token1, token3);
            Assert.AreNotEqual(token2, token3);
        }
コード例 #3
0
        public void AccessTokenAndRefreshTokenAreNotEqual()
        {
            var issuer = new OAuthIssuer();

            var data = new TokenData {
                ConsumerId = 12345, ResourceOwnerId = 12345, Timestamp = DateTime.Now.Ticks
            };

            var accessToken  = issuer.GenerateAccessToken(data);
            var refreshToken = issuer.GenerateRefreshToken(data);

            Assert.AreNotEqual(accessToken, refreshToken);
        }
コード例 #4
0
        public void DecodeAccessToken_DecodesToken()
        {
            var ticks = DateTime.Now.Ticks;
            var data  = new TokenData {
                ConsumerId = 1, ResourceOwnerId = 2, Timestamp = ticks
            };
            var issuer = new OAuthIssuer();

            var token1 = issuer.GenerateAccessToken(data);

            var token = issuer.DecodeAccessToken(token1);

            Assert.AreEqual(2, token.ResourceOwnerId);
            Assert.AreEqual(ticks, token.Timestamp);
        }
コード例 #5
0
        public void GenerateAccessToken_ThrowsExceptionWhenDataIsNull()
        {
            var issuer = new OAuthIssuer();

            issuer.GenerateAccessToken(null);
        }