Beispiel #1
0
        public IEnumerable <RefreshToken> LoadByPage(int page, int pageSize, RefreshTokenFilter filter = null)
        {
            var filterExpression = new RefreshTokenQueryObject(filter).Expression;

            if (page <= 0)
            {
                page = 1;
            }
            if (pageSize <= 0)
            {
                pageSize = 1;
            }
            return(Fetch(filterExpression, page, pageSize));
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            StartLogging();

            var connectionString = "mongodb://localhost";
            var client           = new MongoClient(connectionString);
            var db = client.GetDatabase("ItHappenedDB");

            services.AddOptions();
            services.AddMemoryCache();
            services.Configure <IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting"));
            services.Configure <IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
            services.AddSingleton <IIpPolicyStore, MemoryCacheIpPolicyStore>();
            services.AddSingleton <IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();

            var securityConfiguration = Configuration.GetSection("Security");

            var securitySettings = new SecuritySettings(securityConfiguration["Issue"],
                                                        securityConfiguration["AccessEncryptionKey"],
                                                        securityConfiguration.GetValue <TimeSpan>("AccessExpirationPeriod"),
                                                        securityConfiguration["RefreshEncryptionKey"],
                                                        securityConfiguration.GetValue <TimeSpan>("RefreshExpirationPeriod"));

            var jwtIssuer = new JwtIssuer(securitySettings);

            services.AddSingleton(securitySettings);
            services.AddSingleton <IJwtIssuer>(jwtIssuer);

            var accessTokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer           = false,
                ValidateAudience         = false,
                ValidateLifetime         = true,
                ValidateIssuerSigningKey = true,
                ClockSkew        = TimeSpan.Zero,
                IssuerSigningKey = new SymmetricSecurityKey(
                    Encoding.UTF8.GetBytes(securitySettings.AccessEncryptionKey))
            };

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = accessTokenValidationParameters;
            });

            services
            .AddAuthorization(options =>
            {
                options.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme)
                                        .RequireAuthenticatedUser().Build();
            });

            var accessFilter = new AccessFilter(accessTokenValidationParameters);

            var refreshTokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer           = false,
                ValidateAudience         = false,
                ValidateLifetime         = true,
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(
                    Encoding.UTF8.GetBytes(securitySettings.RefreshEncryptionKey)),
                ClockSkew = TimeSpan.Zero
            };

            var refreshFilter = new RefreshTokenFilter(refreshTokenValidationParameters);

            services.AddSingleton(refreshFilter);
            services.AddSingleton(accessFilter);


            var userRepository  = new UserRepository(db);
            var trackingManager = new TrackingManager(userRepository);

            services.AddSingleton <ITrackingManager>(trackingManager);
            services.AddMvc(o =>
            {
                o.Filters.Add(new ActionFilter());
                o.Filters.Add(new ExceptionFilter());
            });
        }
Beispiel #3
0
 public RefreshTokenQueryObject(RefreshTokenFilter filter)
 {
     if (filter != null)
     {
     }
 }
Beispiel #4
0
        public IEnumerable <RefreshToken> LoadAll(RefreshTokenFilter filter = null)
        {
            var expression = new RefreshTokenQueryObject(filter).Expression;

            return(Fetch(expression));
        }