public static void AddAuthenticationHundredBasicToken(this IServiceCollection services, IConfiguration configuration)
        {
            ValidarConfiguracion(configuration);

            BasicTokenProvider tokenProvider = new BasicTokenProvider(configuration);

            //Obtener secretKey
            var signingKey = tokenProvider.GetSecretKey();

            //Validaciones de Token
            var tokenValidationParameters = tokenProvider.GetValidationParameters();

            //Agregar autenticación
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options => { options.TokenValidationParameters = tokenValidationParameters; })
            .AddCookie(options => {
                options.Cookie.Name      = configuration.GetSection(BasicTokenProviderConfig.CookieSectionName).Value;
                options.TicketDataFormat = new JwtDataFormat(
                    SecurityAlgorithms.HmacSha256, tokenValidationParameters);
            });

            //Agregar Memory Caching
            services.AddMemoryCache();
        }
        public static IApplicationBuilder UseHundredTokenProvider(
            this IApplicationBuilder builder, IConfiguration configuration, IMemoryCache cache)
        {
            ValidarConfiguracion(configuration);
            BasicTokenProvider tokenProvider = new BasicTokenProvider(configuration);

            return(builder.UseMiddleware <BasicTokenProviderMiddleware>(configuration, tokenProvider, cache));
        }
        //Generar tokens previa validación
        public static IApplicationBuilder UseHundredTokenProvider(
            this IApplicationBuilder builder, IConfiguration configuration,
            Func <string, string, Task <ClaimsIdentity> > identityResolver)
        {
            ValidarConfiguracion(configuration);
            BasicTokenProvider tokenProvider = new BasicTokenProvider(configuration);

            tokenProvider.IdentityResolver = identityResolver;
            return(builder.UseMiddleware <BasicTokenProviderMiddleware>(configuration, tokenProvider));
        }
        public BasicTokenProviderMiddleware(
            RequestDelegate next,
            IConfiguration configuration,
            BasicTokenProvider tokenProvider,
            IMemoryCache cache
            )
        {
            this.next          = next;
            this.tokenProvider = tokenProvider;

            var options = this.tokenProvider.GetProviderOptions();

            this.cacheHelper = new MemoryCacheHelper(cache, TimeSpan.FromSeconds(options.Expiration.TotalSeconds));

            this.serializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
        }