Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .AllowAnyMethod()
                                  .AllowCredentials()
                                  .SetIsOriginAllowed((host) => true)
                                  .AllowAnyHeader());
            });

            SymmetricSecurityKey key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SingleTon.getResources("Secret")));

            services.AddAuthentication("OAuth").AddJwtBearer("OAuth", config =>
            {
                config.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidIssuer      = Environment.GetEnvironmentVariable("Host"),
                    ValidAudience    = Environment.GetEnvironmentVariable("Host"),
                    IssuerSigningKey = key,
                };
            });
        }