/// <summary>
        /// Adds the Duende.BFF services to DI
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configureAction"></param>
        /// <returns></returns>
        public static BffBuilder AddBff(this IServiceCollection services, Action <BffOptions> configureAction = null)
        {
            var opts = new BffOptions();

            configureAction?.Invoke(opts);
            services.AddSingleton(opts);

            services.AddHttpProxy();
            services.AddAccessTokenManagement();

            services.TryAddSingleton <IHttpMessageInvokerFactory, DefaultHttpMessageInvokerFactory>();
            services.TryAddSingleton <IHttpTransformerFactory, DefaultHttpTransformerFactory>();

            services.AddTransient <ILoginService, DefaultLoginService>();
            services.AddTransient <ILogoutService, DefaultLogoutService>();
            services.AddTransient <IUserService, DefaultUserService>();
            services.AddTransient <IBackchannelLogoutService, DefaultBackchannelLogoutService>();
            services.TryAddTransient <ISessionRevocationService, NopSessionRevocationService>();

            #if NET5_0
            services.AddTransient <IAuthorizationMiddlewareResultHandler, BffAuthorizationMiddlewareResultHandler>();
            #endif

            return(new BffBuilder(services));
        }
Beispiel #2
0
        /// <summary>
        /// Adds the Duende.BFF services to DI
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configureAction"></param>
        /// <returns></returns>
        public static BffBuilder AddBff(this IServiceCollection services, Action <BffOptions> configureAction = null)
        {
            var opts = new BffOptions();

            configureAction?.Invoke(opts);
            services.AddSingleton(opts);

            services.AddAccessTokenManagement();

            // management endpoints
            services.AddTransient <ILoginService, DefaultLoginService>();
            services.AddTransient <ILogoutService, DefaultLogoutService>();
            services.AddTransient <IUserService, DefaultUserService>();
            services.AddTransient <IBackchannelLogoutService, DefaultBackchannelLogoutService>();
            services.AddTransient <IDiagnosticsService, DefaultDiagnosticsService>();

            // session management
            services.TryAddTransient <ISessionRevocationService, NopSessionRevocationService>();

            // cookie configuration
            #if NET6_0_OR_GREATER
            services.AddSingleton <IPostConfigureOptions <CookieAuthenticationOptions>, PostConfigureSlidingExpirationCheck>();
            #else
            services.AddSingleton <IPostConfigureOptions <CookieAuthenticationOptions>, PostConfigureApplicationValidatePrincipal>();
            #endif

            services.AddSingleton <IPostConfigureOptions <CookieAuthenticationOptions>, PostConfigureApplicationCookieRevokeRefreshToken>();

            #if NET5_0_OR_GREATER
            services.AddTransient <IAuthorizationMiddlewareResultHandler, BffAuthorizationMiddlewareResultHandler>();
            #endif

            return(new BffBuilder(services));
        }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="options"></param>
 /// <param name="ticketStore"></param>
 /// <param name="sessionStore"></param>
 /// <param name="tokenEndpoint"></param>
 /// <param name="logger"></param>
 public SessionRevocationService(BffOptions options, IServerTicketStore ticketStore, IUserSessionStore sessionStore, ITokenEndpointService tokenEndpoint, ILogger <SessionRevocationService> logger)
 {
     _options       = options;
     _ticketStore   = ticketStore;
     _sessionStore  = sessionStore;
     _tokenEndpoint = tokenEndpoint;
     _logger        = logger;
 }
Beispiel #4
0
    public static void Initalize(ILoggerFactory loggerFactory, BffOptions options)
    {
        _logger = loggerFactory.CreateLogger("Duende.Bff");

        var key = options.LicenseKey ?? LoadFromFile();

        _license = ValidateKey(key);
    }
Beispiel #5
0
 public static void CheckForBffMiddleware(this HttpContext context, BffOptions options)
 {
     if (options.EnforceBffMiddleware)
     {
         var found = context.Items.TryGetValue(Constants.BffMiddlewareMarker, out _);
         if (!found)
         {
             throw new InvalidOperationException(
                       "The BFF middleware is missing in the pipeline. Add 'app.UseBff' after 'app.UseRouting' but before 'app.UseAuthorization'");
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="options">The BFF options</param>
 /// <param name="transformBuilder">The YARP transform builder</param>
 public DefaultHttpTransformerFactory(BffOptions options, ITransformBuilder transformBuilder)
 {
     Options          = options;
     TransformBuilder = transformBuilder;
 }
Beispiel #7
0
 /// <summary>
 /// Constructor for SessionCleanupHost.
 /// </summary>
 public SessionCleanupHost(IServiceProvider serviceProvider, BffOptions options, ILogger <SessionCleanupHost> logger)
 {
     _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _options         = options;
     _logger          = logger;
 }
Beispiel #8
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 /// <param name="logger"></param>
 public BffMiddleware(RequestDelegate next, BffOptions options, ILogger <BffMiddleware> logger)
 {
     _next    = next;
     _options = options;
     _logger  = logger;
 }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="options"></param>
 public DefaultSilentLoginService(BffOptions options)
 {
     _options = options;
 }
Beispiel #10
0
 public TicketStoreShim(IHttpContextAccessor httpContextAccessor)
 {
     _httpContextAccessor = httpContextAccessor;
     _options             = _httpContextAccessor.HttpContext !.RequestServices.GetRequiredService <BffOptions>();
 }
Beispiel #11
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="options"></param>
 /// <param name="loggerFactory"></param>
 public DefaultUserService(BffOptions options, ILoggerFactory loggerFactory)
 {
     Options = options;
     Logger  = loggerFactory.CreateLogger(LogCategories.ManagementEndpoints);
 }
Beispiel #12
0
    public static bool CheckAntiForgeryHeader(this HttpContext context, BffOptions options)
    {
        var antiForgeryHeader = context.Request.Headers[options.AntiForgeryHeaderName].FirstOrDefault();

        return(antiForgeryHeader != null && antiForgeryHeader == options.AntiForgeryHeaderValue);
    }
Beispiel #13
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="options"></param>
 /// <param name="authenticationAuthenticationSchemeProviderProvider"></param>
 public DefaultLogoutService(BffOptions options, IAuthenticationSchemeProvider authenticationAuthenticationSchemeProviderProvider)
 {
     Options = options;
     AuthenticationSchemeProvider = authenticationAuthenticationSchemeProviderProvider;
 }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="options"></param>
 /// <param name="logger"></param>
 public AccessTokenTransformProvider(BffOptions options, ILogger <AccessTokenTransformProvider> logger)
 {
     _options = options;
     _logger  = logger;
 }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="bffOptions"></param>
 /// <param name="authOptions"></param>
 /// <param name="logger"></param>
 public PostConfigureApplicationValidatePrincipal(BffOptions bffOptions, IOptions <AuthenticationOptions> authOptions, ILogger <PostConfigureApplicationValidatePrincipal> logger)
 {
     _options = bffOptions;
     _scheme  = authOptions.Value.DefaultAuthenticateScheme ?? authOptions.Value.DefaultScheme;
     _logger  = logger;
 }
Beispiel #16
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="bffOptions"></param>
 /// <param name="authOptions"></param>
 /// <param name="logger"></param>
 public PostConfigureApplicationCookieRevokeRefreshToken(BffOptions bffOptions, IOptions <AuthenticationOptions> authOptions, ILogger <PostConfigureApplicationCookieRevokeRefreshToken> logger)
 {
     _options = bffOptions;
     _scheme  = authOptions.Value.DefaultAuthenticateScheme ?? authOptions.Value.DefaultScheme;
     _logger  = logger;
 }