コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CatalogContextSeedData seeder, ILoggerFactory loggerFactory)
        {
            if (env.IsEnvironment("Development"))
            {
                app.UseDeveloperExceptionPage();
            }

            loggerFactory.AddDebug(LogLevel.Warning);

            app.UseStaticFiles();


            // JWT Middleware

            var options = new JwtBearerOptions
            {
                Audience  = _config["auth0:clientId"],
                Authority = $"https://{_config["auth0:domain"]}/"
            };

            app.UseJwtBearerAuthentication(options);

            Mapper.Initialize(config =>
            {
                config.CreateMap <Component, ComponentViewModel>().ReverseMap();
                config.CreateMap <Sample, SampleViewModel>().ReverseMap();
            });

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "Index" }
                    );
            });

            //
            // This gets called only at server startup and only of the database does not exist
            // (these test are a part of the CreateSeedData method, which also gets access to the
            // CatalogContest reference in the seeder class.
            //
            seeder.CreateSeedData();
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CatalogContextSeedData seeder, ILoggerFactory loggerFactory, IOptions <Auth0Settings> auth0Settings)
        {
            if (env.IsEnvironment("Development"))
            {
                app.UseDeveloperExceptionPage();
            }

            loggerFactory.AddDebug(LogLevel.Warning);

            app.UseStaticFiles();

            // Add the cookie middleware
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true
            });

            var cliendid = auth0Settings.Value.ClientId;
            var secret   = auth0Settings.Value.ClientSecret;

            var options = new OpenIdConnectOptions("Auth0")
            {
                // Set the authority to your Auth0 domain
                Authority = $"https://{auth0Settings.Value.Domain}",

                // Configure the Auth0 Client ID and Client Secret
                ClientId     = auth0Settings.Value.ClientId,
                ClientSecret = auth0Settings.Value.ClientSecret,

                // Do not automatically authenticate and challenge
                AutomaticAuthenticate = false,
                AutomaticChallenge    = false,

                // Set response type to code
                ResponseType = "code",

                // Set the callback path, so Auth0 will call back to http://localhost:8000/signin-auth0
                // Also ensure that you have added the URL as an Allowed Callback URL in your Auth0 dashboard
                CallbackPath = new PathString("/signin-auth0"),

                // Configure the Claims Issuer to be Auth0
                ClaimsIssuer = "Auth0",

                Events = new OpenIdConnectEvents
                {
                    // handle the logout redirection
                    OnRedirectToIdentityProviderForSignOut = (context) =>
                    {
                        var logoutUri = $"https://{auth0Settings.Value.Domain}/v2/logout?client_id={auth0Settings.Value.ClientId}";

                        var postLogoutUri = context.Properties.RedirectUri;
                        if (!string.IsNullOrEmpty(postLogoutUri))
                        {
                            if (postLogoutUri.StartsWith("/"))
                            {
                                // transform to absolute
                                var request = context.Request;
                                postLogoutUri = request.Scheme + "://" + request.Host + request.PathBase + postLogoutUri;
                            }
                            logoutUri += $"&returnTo={ Uri.EscapeDataString(postLogoutUri)}";
                        }

                        context.Response.Redirect(logoutUri);
                        context.HandleResponse();

                        return(Task.CompletedTask);
                    }
                }
            };

            options.Scope.Clear();
            options.Scope.Add("openid");
            app.UseOpenIdConnectAuthentication(options);

            Mapper.Initialize(config =>
            {
                config.CreateMap <Component, ComponentViewModel>().ReverseMap();
                config.CreateMap <Sample, SampleViewModel>().ReverseMap();
            });

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "Index" }
                    );
            });

            //
            // This gets called only at server startup and only of the database does not exist
            // (these test are a part of the CreateSeedData method, which also gets access to the
            // CatalogContest reference in the seeder class.
            //
            seeder.CreateSeedData();
        }