Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(jwt =>
            {
                jwt.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
                {
                    ValidateAudience = false,
                    ValidateIssuer   = false,
                    IssuerSigningKey = AuthenticationUtilities.GetIssuerKey()
                };
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            var contextInfo = new ContextInfo
            {
                ConnectionString = Configuration["StorageConnectionString"]
            };
            var contextProvider = new ContextProvider(contextInfo);

            ContextProvider.Instance = contextProvider;
        }