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.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            // Configure AutoMapper
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

            // Configure DI
            RepositoryMapping.InitMap(services);
            ServiceMapping.InitMap(services);



            // Configure identity server
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            services.AddAuthentication(options =>
            {
                // Notice the schema name is case sensitive [ cookies != Cookies ]
                options.DefaultScheme          = "cookies";
                options.DefaultChallengeScheme = "oidc";
            })

            .AddCookie("cookies", options => options.ForwardDefaultSelector = ctx => ctx.Request.Path.StartsWithSegments("/api") ? "jwt" : "cookies")
            .AddJwtBearer("jwt", options =>
            {
                options.Authority            = "https://localhost:44359";
                options.Audience             = "api1";
                options.RequireHttpsMetadata = false;
            })
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme         = "cookies";
                options.Authority            = "https://localhost:44359";
                options.RequireHttpsMetadata = true;
                options.ClientId             = "mvc";
                options.SaveTokens           = true;

                options.ClientSecret = "secret";
                options.ResponseType = "code id_token";
                options.GetClaimsFromUserInfoEndpoint = true;
                options.Scope.Add("api1");
                options.Scope.Add("offline_access");

                options.ForwardDefaultSelector = ctx => ctx.Request.Path.StartsWithSegments("/api") ? "jwt" : "oidc";
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Example #2
0
 public ControllerMapping CreateController(string usingBlock, string nameSpace, RepositoryMapping repo)
 {
     return(new ControllerMapping(usingBlock, nameSpace, $"{repo.Poco.ClassName}sController", repo));
 }