public static IServiceCollection AddCelebrityMvc(this IServiceCollection services, IConfiguration configuration)
 {
     return(services
            .AddOptions()
            .Configure <Global>(configuration.GetSection(nameof(Global)))
            .AddAuthentication(ServiceCollectionExtensions.Authentication)
            .AddOpenIdConnect(ServiceCollectionExtensions.OpenId(configuration))
            .AddCookie()
            .Services
            .AddMvc(ServiceCollectionExtensions.Mvc)
            .AddJsonOptions(ServiceCollectionExtensions.Json)
            .Services);
 }
        private static Action <OpenIdConnectOptions> OpenId(IConfiguration configuration)
        {
            return(options =>
            {
                var global = configuration.Get <Global>();
                configuration.GetSection(nameof(Global)).Bind(global);

                options.Authority = new UriBuilder(Uri.UriSchemeHttps, global.AuthOpenId.Domain).Uri.AbsoluteUri;
                options.CallbackPath = new PathString(global.AuthOpenId.CallbackUrl);
                options.ClaimsIssuer = global.AuthOpenId.ClaimsIssuer;
                options.ClientId = global.AuthOpenId.ClientId;
                options.ClientSecret = global.AuthOpenId.ClientSecret;
                options.ResponseType = global.AuthOpenId.ResponseType;

                options.Scope.Clear();
                options.Scope.Add(global.AuthOpenId.Scope);

                options.Events = new OpenIdConnectEvents
                {
                    OnRedirectToIdentityProviderForSignOut = ServiceCollectionExtensions.SignOut(global),
                    OnUserInformationReceived = ServiceCollectionExtensions.User()
                };
            });
        }