public void GetUserAccessTokenCancellationTokenOverloadWithNullUsernameThrowsArgumentNullException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);
            string nullUsername = null;

            // Act
            
            // Assert
            Assert.Throws<ArgumentNullException>(() => accessTokenClient.GetUserAccessToken(nullUsername, Password, UserScope, CancellationToken.None));
        }
        public void GetUserAccessTokenWithEmptyUsernameThrowsArgumentException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);
            var emptyUsername = string.Empty;

            // Act

            // Assert
            Assert.Throws<ArgumentException>(() => accessTokenClient.GetUserAccessToken(emptyUsername, Password, UserScope));
        }
        public void GetUserAccessTokenCancellationTokenOverloadWithValidCredentialsButInvalidScopeThrowsException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);

            // Act
            var task = accessTokenClient.GetUserAccessToken(Username, Password, "invalid user scope", CancellationToken.None);

            // Assert
            Assert.Throws <AggregateException>(() => task.Wait());
        }
        public void GetUserAccessTokenCancellationTokenOverloadWithNullScopeDoesNotThrowException()
        {
            // Arrange
            var    accessTokenClient = new AccessTokenClient(ServerConfiguration);
            string nullScope         = null;

            // Act

            // Assert
            Assert.DoesNotThrow(() => accessTokenClient.GetUserAccessToken(Username, Password, nullScope, CancellationToken.None));
        }
        public void GetUserAccessTokenCancellationTokenOverloadWithValidCredentialsButInvalidScopeThrowsException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);

            // Act
            var task = accessTokenClient.GetUserAccessToken(Username, Password, "invalid user scope", CancellationToken.None);

            // Assert
            Assert.Throws<AggregateException>(() => task.Wait());
        }
        public void GetUserAccessTokenWithNullScopeDoesNotThrowException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);
            string nullScope = null;

            // Act

            // Assert
            Assert.DoesNotThrow(() => accessTokenClient.GetUserAccessToken(Username, Password, nullScope));
        }
Exemple #7
0
        public void GetUserAccessTokenWithNullPasswordThrowsArgumentNullException()
        {
            // Arrange
            var    accessTokenClient = new AccessTokenClient(ServerConfiguration);
            string nullPassword      = null;

            // Act

            // Assert
            Assert.Throws <ArgumentNullException>(() => accessTokenClient.GetUserAccessToken(Username, nullPassword, UserScope));
        }
Exemple #8
0
        public void GetUserAccessTokenCancellationTokenOverloadWithEmptyUsernameThrowsArgumentException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);
            var emptyUsername     = string.Empty;

            // Act

            // Assert
            Assert.Throws <ArgumentException>(() => accessTokenClient.GetUserAccessToken(emptyUsername, Password, UserScope, CancellationToken.None));
        }
Exemple #9
0
        public void GetUserAccessTokenWithEmptyPasswordThrowsArgumentException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);
            var emptyPassword     = string.Empty;

            // Act

            // Assert
            Assert.Throws <ArgumentException>(() => accessTokenClient.GetUserAccessToken(Username, emptyPassword, UserScope));
        }
        public void GetUserAccessTokenCancellationTokenOverloadWithValidCredentialsReturnsAccessToken()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);

            // Act
            var task = accessTokenClient.GetUserAccessToken(Username, Password, UserScope, CancellationToken.None);
            task.Wait();

            // Assert
            Assert.NotNull(task.Result);
        }
        public void GetUserAccessTokenCancellationTokenOverloadWithValidCredentialsReturnsAccessToken()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);

            // Act
            var task = accessTokenClient.GetUserAccessToken(Username, Password, UserScope, CancellationToken.None);

            task.Wait();

            // Assert
            Assert.NotNull(task.Result);
        }
        public void RefreshTokenCancellationTokenOverloadReturnsNewAccessToken()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);

            // Act
            var task = accessTokenClient.GetUserAccessToken(Username, Password, UserScope, CancellationToken.None);

            task.Wait();

            var refreshTokenTask = accessTokenClient.RefreshToken(task.Result.RefreshToken, CancellationToken.None);

            refreshTokenTask.Wait();

            // Assert
            Assert.NotNull(refreshTokenTask.Result);
        }
Exemple #13
0
        public async Task <GetAccessTokenResponse> GetAccessToken(string username, string password, CancellationToken cancellationToken)
        {
            var accessTokenClient = new AccessTokenClient(new OAuthServerConfiguration(_appSettings.Identity.Host, "/auth/token",
                                                                                       _appSettings.Identity.ClientId, _appSettings.Identity.ClientSecret));

            var tokenResponse = await accessTokenClient.GetUserAccessToken(username, password, "", cancellationToken).ConfigureAwait(false);

            if (tokenResponse.IsError)
            {
                return(new GetAccessTokenResponse {
                    AccessToken = null, Error = tokenResponse.Error
                });
            }

            var token = tokenResponse.AccessToken;

            await _accessTokenStore.SaveClientAccessToken(_appSettings.Identity.ClientId, _appSettings.ServiceId,
                                                          token, cancellationToken);

            return(new GetAccessTokenResponse {
                AccessToken = token
            });
        }
        public void GetUserAccessTokenWithNullPasswordThrowsArgumentNullException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);
            string nullPassword = null;

            // Act

            // Assert
            Assert.Throws<ArgumentNullException>(() => accessTokenClient.GetUserAccessToken(Username, nullPassword, UserScope));
        }
        public void GetUserAccessTokenCancellationTokenOverloadWithEmptyPasswordThrowsArgumentException()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);
            var emptyPassword = string.Empty;

            // Act

            // Assert
            Assert.Throws<ArgumentException>(() => accessTokenClient.GetUserAccessToken(Username, emptyPassword, UserScope, CancellationToken.None));
        }
        public void RefreshTokenCancellationTokenOverloadReturnsNewAccessToken()
        {
            // Arrange
            var accessTokenClient = new AccessTokenClient(ServerConfiguration);

            // Act
            var task = accessTokenClient.GetUserAccessToken(Username, Password, UserScope, CancellationToken.None);
            task.Wait();

            var refreshTokenTask = accessTokenClient.RefreshToken(task.Result.RefreshToken, CancellationToken.None);
            refreshTokenTask.Wait();

            // Assert
            Assert.NotNull(refreshTokenTask.Result);
        }