Esempio n. 1
0
        /// <summary>
        /// Adds the required services in order to notify the consumer about scopes that have been revoked or granted.
        /// </summary>
        /// <typeparam name="TParsedScopeNotificationService">The type of provided implementation of <see cref="IParsedScopeNotificationService"/>.</typeparam>
        /// <param name="builder">The <see cref="IIdentityServerBuilder"/> builder.</param>
        /// <param name="configureAction">Configures options for <see cref="IParsedScopeNotificationService"/>.</param>
        public static IIdentityServerBuilder AddParsedScopeNotifications <TParsedScopeNotificationService>(this IIdentityServerBuilder builder, Action <ParsedScopeNotificationOptions> configureAction = null)
            where TParsedScopeNotificationService : class, IParsedScopeNotificationService
        {
            var existingService = builder.Services.Where(x => x.ServiceType == typeof(IParsedScopeNotificationService)).LastOrDefault();

            if (existingService == null)
            {
                var configuration = builder.Services.BuildServiceProvider().GetRequiredService <IConfiguration>();
                var options       = new ParsedScopeNotificationOptions {
                    Endpoint = configuration["IdentityServer:ScopeNotificationEndpoint"]
                };
                configureAction?.Invoke(options);
                if (string.IsNullOrEmpty(options.Endpoint))
                {
                    throw new Exception($"Configuration for {nameof(AddParsedScopeNotifications)} failed. Must provide a IdentityServer:ScopeNotificationEndpoint setting.");
                }
                builder.Services.AddSingleton(options);
                builder.AddConsentServiceWithParsedScopeNotifications();
                builder.AddPersistedGrantServiceWithParsedScopeNotifications();
                builder.Services.AddHttpClient <IParsedScopeNotificationService, TParsedScopeNotificationService>()
                .SetHandlerLifetime(TimeSpan.FromMinutes(5));
            }
            return(builder);
        }