Ejemplo n.º 1
0
        public async Task PostToken_AuthorizationTokenClientNotAllowed_Return403()
        {
            var scope = $"{_settings.ApiAppIdUri}/{_settings.AdminClientId}/{_settings.Scope}";
            // Arrange
            var tokenFromUnauthorizedClient = await Utilities.GetUserAccessToken(_settings.TestUsername, _settings.TestPassword, _settings.AdminClientId, _settings.AdminClientSecret,
                                                                                 _configuration[ConfigurationName.OAuthAuthority], scope).ConfigureAwait(false);

            // Temporary workaround the consent for new AAD app in each test run
            // TODO: Add UI automation to grant consent for new AAD app in each test run
            var customizedAppConfiguration = new Dictionary <string, string>(_defaultConfigurations);

            customizedAppConfiguration[ConfigurationName.IdentifierUri] = $"{_settings.AdminClientId}";
            var factory = _aadInstance.ConfigureWebApplicationFactory(customizedAppConfiguration);
            var client  = factory.CreateDefaultClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenFromUnauthorizedClient);

            // Act
            var requestBody = new PostTokenRequestBody
            {
                scope      = DefaultGraphScope,
                grant_type = PostTokenGrantType.SsoToken,
            };
            var result = await PostToAuthTokenApi <ProblemDetails>(client, requestBody);

            // Assert
            Assert.AreEqual(HttpStatusCode.Forbidden, result.Response.StatusCode);
        }
Ejemplo n.º 2
0
        public AuthControllerTests()
        {
            _aadInstance   = AadInstanceSetUp.defaultAadInstance;
            _settings      = _aadInstance.IntegrationTestSettings;
            _configuration = _aadInstance.Configuration;
            _teamsAadInfo  = _aadInstance.TeamsAadInfo;

            _defaultConfigurations = new Dictionary <string, string>()
            {
                [ConfigurationName.ClientId]           = _configuration[ConfigurationName.ClientId],
                [ConfigurationName.ClientSecret]       = _configuration[ConfigurationName.ClientSecret],
                [ConfigurationName.OAuthAuthority]     = _configuration[ConfigurationName.OAuthAuthority],
                [ConfigurationName.IdentifierUri]      = _teamsAadInfo.IdentifierUri,
                [ConfigurationName.AadMetadataAddress] = _configuration[ConfigurationName.AadMetadataAddress]
            };

            replaceTenantId();
            _defaultFactory = _aadInstance.ConfigureWebApplicationFactory(_defaultConfigurations);
        }