示例#1
0
        public async Task Login()
        {
            var url = new RequestUrl(this.Services.Authority + "/connect/authorize")
                      .CreateAuthorizeUrl(
                this.Services.Client.Id,
                "id_token token",
                "openid profile " + this.Services.ApiResource.Name,
                this.Services.Client.RedirectUris.First(),
                "state",
                "nonce");

            var automation = new BrowserAutomation(this.CurrentUser.Username, this.CurrentUser.Password);
            await automation.NavigateToLoginAsync(url).ConfigureAwait(false);

            var authorizeResponse = await automation.LoginToAuthorizationServerAndCaptureRedirectAsync().ConfigureAwait(false);

            authorizeResponse.IsError.Should().BeFalse();
            this.Services.ApolloClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authorizeResponse.AccessToken);

            var handler = new JwtSecurityTokenHandler();

            if (!handler.CanReadToken(authorizeResponse.AccessToken))
            {
                throw new InvalidOperationException("Unable to read JWT token after logging into Ironclad");
            }

            var token = handler.ReadJwtToken(authorizeResponse.AccessToken);

            this.UserId = token.Claims.FirstOrDefault(x => x.Type == "sub")?.Value;
        }
示例#2
0
        public async Task CanUseImplicitClient()
        {
            // arrange
            var httpClient = new ClientsHttpClient(this.Authority, this.Handler);
            var client     = new Client
            {
                Id   = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture),
                Name = $"{nameof(ClientManagement)}.{nameof(this.CanUseImplicitClient)} (integration test)",
                AllowedCorsOrigins          = { "http://localhost:5006" },
                RedirectUris                = { "http://localhost:5006/redirect" },
                AllowedScopes               = { "openid", "profile", "sample_api" },
                AllowAccessTokensViaBrowser = true,
                AllowedGrantTypes           = { "implicit" },
                RequireConsent              = false,
            };

            await httpClient.AddClientAsync(client).ConfigureAwait(false);

            // act
            var url = new RequestUrl(this.Authority + "/connect/authorize")
                      .CreateAuthorizeUrl(client.Id, "id_token token", "openid profile sample_api", client.RedirectUris.First(), "state", "nonce");

            var automation = new BrowserAutomation("admin", "password");
            await automation.NavigateToLoginAsync(url).ConfigureAwait(false);

            var authorizeResponse = await automation.LoginToAuthorizationServerAndCaptureRedirectAsync().ConfigureAwait(false);

            // assert
            authorizeResponse.IsError.Should().BeFalse();
        }
示例#3
0
        private async void SubmitOrderExecute()
        {
            if (CancelIfDuplicateOrder())
            {
                return;
            }

            try
            {
                var selenium = new BrowserAutomation(Pass.CompanyCode, Pass.UserId, Pass.Password);
                await Update(selenium.OrderBentoes(Bentoes.Where(b => b.ToBeOrdered)));
                await Update(LoadMenu(selectedDay));
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(ex.Message, "BentoEx - Browser automation failed");
                return;
            }
        }
示例#4
0
        public async Task CanUseHybridClient()
        {
            // arrange
            var httpClient = new ClientsHttpClient(this.Authority, this.Handler);
            var client     = new Client
            {
                Id   = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture),
                Name = $"{nameof(ClientManagement)}.{nameof(this.CanUseHybridClient)} (integration test)",
                RequireClientSecret = false,
                AllowedGrantTypes   = { "hybrid" },
                RequirePkce         = true,
                RedirectUris        = { "http://127.0.0.1" },
                AllowOfflineAccess  = true,
                AllowedScopes       = { "openid", "profile", "sample_api" },
                RequireConsent      = false,
            };

            await httpClient.AddClientAsync(client).ConfigureAwait(false);

            // act
            var automation = new BrowserAutomation("admin", "password");
            var browser    = new Browser(automation);
            var options    = new OidcClientOptions
            {
                Authority    = this.Authority,
                ClientId     = client.Id,
                RedirectUri  = $"http://127.0.0.1:{browser.Port}",
                Scope        = "openid profile sample_api offline_access",
                FilterClaims = false,
                Browser      = browser,
                Policy       = new Policy {
                    Discovery = new DiscoveryPolicy {
                        ValidateIssuerName = false
                    }
                }
            };

            var oidcClient = new OidcClient(options);
            var result     = await oidcClient.LoginAsync(new LoginRequest()).ConfigureAwait(false);

            // assert
            result.IsError.Should().BeFalse();
        }
        public async Task CanUseUser()
        {
            // arrange
            var httpClient = new UsersHttpClient(this.Authority, this.Handler);
            var user       = new User
            {
                Username = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture),
                Password = "******",
            };

            await httpClient.AddUserAsync(user).ConfigureAwait(false);

            // act
            var automation = new BrowserAutomation(user.Username, user.Password);
            var browser    = new Browser(automation);
            var options    = new OidcClientOptions
            {
                Authority    = this.Authority,
                ClientId     = "auth_console",
                RedirectUri  = $"http://127.0.0.1:{browser.Port}",
                Scope        = "openid profile auth_api offline_access",
                FilterClaims = false,
                Browser      = browser,
                Policy       = new Policy {
                    Discovery = new DiscoveryPolicy {
                        ValidateIssuerName = false
                    }
                }
            };

            var oidcClient = new OidcClient(options);
            var result     = await oidcClient.LoginAsync(new LoginRequest()).ConfigureAwait(false);

            // assert
            result.IsError.Should().BeFalse();
        }