public async Task <RunningWebServerInfo> StartAuthorizeRequestAsync(
            AuthorizeRequestData request,
            CancellationToken cancellationToken)
        {
            var id = Guid.NewGuid();

            RunningWebServerInfo server = await _authWebServer.StartAsync(
                new StartWebServerOptions(
                    Guid.NewGuid(), request.Port)
            {
                Title       = $"{request.Authority} ({request.ClienId})",
                SetupAction = (services) =>
                {
                    services.AddSingleton(request);
                    services.AddSingleton <IBoostCommandContext>(_commandContext);
                }
            }, cancellationToken);

            return(server);
        }
        public async Task<StartAuthorizationRequestPayload> StartAuthorizationRequestAsync(
            [Service] IAuthorizeRequestService authService,
            AuthorizeRequestInput input,
            CancellationToken cancellationToken)
        {
            var request = new AuthorizeRequestData(
                input.Authority,
                input.ClientId,
                input.Secret,
                input.Scopes,
                input.UsePkce)
            {
                Port = input.Port,
                SaveTokens = input.SaveTokens,
                RequestId = input.RequestId
            };

            RunningWebServerInfo session = await authService.StartAuthorizeRequestAsync(
                request,
                cancellationToken);

            return new StartAuthorizationRequestPayload(session);
        }
 public StartAuthorizationRequestPayload(RunningWebServerInfo server)
 {
     Server = server;
 }
Exemple #4
0
        public async Task <RunningWebServerInfo> StartAsync(
            StartWebServerOptions serverOptions,
            CancellationToken cancellationToken)
        {
            var url = $"http://localhost:{serverOptions.Port}";

            IHost _host = Host.CreateDefaultBuilder()
                          .UseSerilog()
                          .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseUrls(url);
                webBuilder.UseStartup <AuthStartup>();
            })
                          .ConfigureServices((ctx, services) =>
            {
                JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
                serverOptions.SetupAction?.Invoke(services);

                services.AddControllers();

                services.AddGraphQLServer()
                .AddQueryType(d => d.Name(RootTypes.Query))
                .AddType <AuthQueries>();

                services.AddSingleton <
                    IAuthenticationSessionService,
                    AuthenticationSessionService>();
                services.AddSingleton <ITokenAnalyzer, TokenAnalyzer>();
                services.AddSingleton <IIdentityService, IdentityService>();
                services.AddSingleton <IAuthTokenStore, UserDataAuthTokenStore>();
                services.AddSingleton <ISettingsStore, SettingsStore>();

                services.AddSingleton <ICertificateManager, CertificateManager>();
                services.AddUserDataProtection();
                services.AddSingleton(c =>
                {
                    return(c.GetRequiredService <IBoostCommandContext>()
                           .Services.GetRequiredService <IUserDataProtector>());
                });

                services.AddHttpContextAccessor();
                services.AddSameSiteOptions();
                services.AddOptions <OpenIdConnectOptions>("oidc")
                .Configure <AuthorizeRequestData>((options, authData) =>
                {
                    options.Authority    = authData.Authority;
                    options.ClientSecret = authData.Secret;
                    options.ClientId     = authData.ClienId;

                    options.Scope.Clear();
                    foreach (string scope in authData.Scopes)
                    {
                        options.Scope.Add(scope);
                    }
                });

                services.AddOptions <FileAuthenticationOptions>(
                    FileAuthenticationDefaults.AuthenticationScheme)
                .Configure <AuthorizeRequestData>((options, authData) =>
                {
                    options.SaveTokens = authData.SaveTokens;
                    options.Filename   = (authData.RequestId != null) ?
                                         $"R-{authData.RequestId}" :
                                         $"S-{serverOptions.Id.ToString("N").Substring(0, 8)}";
                });

                services.AddAuthentication(options =>
                {
                    options.DefaultScheme          = FileAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultChallengeScheme = "oidc";
                })
                .AddFile()
                .AddOpenIdConnect("oidc", options =>
                {
                    options.ResponseType = "code";
                    options.SaveTokens   = true;
                    options.GetClaimsFromUserInfoEndpoint = false;
                    options.TokenValidationParameters     = new TokenValidationParameters
                    {
                        NameClaimType = JwtClaimTypes.Name,
                        RoleClaimType = JwtClaimTypes.Role,
                    };
                });

                services.AddHttpClient();
            })

                          .Build();

            await _host.StartAsync(cancellationToken);

            RunningWebServerInfo server = new RunningWebServerInfo(serverOptions.Id, url)
            {
                Title = serverOptions.Title
            };

            _hosts.Add(server, _host);

            return(server);
        }