当前位置: 首页>>代码示例>>C#>>正文


C# IApplicationBuilder.UseOpenIdConnectServer方法代码示例

本文整理汇总了C#中IApplicationBuilder.UseOpenIdConnectServer方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseOpenIdConnectServer方法的具体用法?C# IApplicationBuilder.UseOpenIdConnectServer怎么用?C# IApplicationBuilder.UseOpenIdConnectServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IApplicationBuilder的用法示例。


在下文中一共展示了IApplicationBuilder.UseOpenIdConnectServer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        public void Configure(IApplicationBuilder app) {
            app.UseDefaultFiles();

            app.UseStaticFiles();

            // Add a new middleware validating access tokens.
            app.UseOAuthValidation(options => {
                options.Events = new OAuthValidationEvents {
                    // Note: for SignalR connections, the default Authorization header does not work,
                    // because the WebSockets JS API doesn't allow setting custom parameters.
                    // To work around this limitation, the access token is retrieved from the query string.
                    OnRetrieveToken = context => {
                        context.Token = context.Request.Query["access_token"];

                        return Task.FromResult(0);
                    }
                };
            });

            app.UseSignalR<SimpleConnection>("/signalr");

            // Add a new middleware issuing access tokens.
            app.UseOpenIdConnectServer(options => {
                options.Provider = new AuthenticationProvider();

                // Enable the token endpoint.
                options.TokenEndpointPath = "/connect/token";
                options.AllowInsecureHttp = true;
            });
        }
开发者ID:pierre-weceipt,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:30,代码来源:Startup.cs

示例2: Configure

        public void Configure(IApplicationBuilder app) {
            // To test this sample with Postman, use the following settings:
            // 
            // * Authorization URL: http://localhost:6500/connect/authorize
            // * Access token URL: http://localhost:6500/connect/token
            // * Client ID: postman
            // * Client secret: [blank] (not used with public clients)
            // * Scope: openid email profile roles
            // * Grant type: authorization code
            // * Request access token locally: yes

            app.UseDeveloperExceptionPage();

            app.UseStaticFiles();

            app.UseOAuthValidation();

            app.UseOpenIdConnectServer(options => {
                options.Provider = new AuthorizationProvider();

                // Enable the authorization and token endpoints.
                options.AuthorizationEndpointPath = "/connect/authorize";
                options.TokenEndpointPath = "/connect/token";
                options.AllowInsecureHttp = true;
            });

            app.UseMvc();

            app.UseWelcomePage();
        }
开发者ID:pierre-weceipt,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:30,代码来源:Startup.cs

示例3: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment environment, ILoggerFactory factory) {
            factory.AddConsole();
            factory.AddDebug();

            app.UseIISPlatformHandler();

            if (environment.IsDevelopment()) {
                app.UseDeveloperExceptionPage();
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();

            // Add a new middleware validating access tokens.
            app.UseJwtBearerAuthentication(options => {
                // Automatic authentication must be enabled
                // for SignalR to receive the access token.
                options.AutomaticAuthenticate = true;

                // Automatically disable the HTTPS requirement for development scenarios.
                options.RequireHttpsMetadata = !environment.IsDevelopment();

                // Note: the audience must correspond to the address of the SignalR server.
                options.Audience = "http://localhost:5000/";

                // Note: the authority must match the address of the identity server.
                options.Authority = "http://localhost:5000/";

                options.Events = new JwtBearerEvents {
                    // Note: for SignalR connections, the default Authorization header does not work,
                    // because the WebSockets JS API doesn't allow setting custom parameters.
                    // To work around this limitation, the access token is retrieved from the query string.
                    OnReceivingToken = context => {
                        // Note: when the token is missing from the query string,
                        // context.Token is null and the JWT bearer middleware will
                        // automatically try to retrieve it from the Authorization header.
                        context.Token = context.Request.Query["access_token"];

                        return Task.FromResult(0);
                    }
                };
            });

            app.UseWebSockets();

            app.UseSignalR<SimpleConnection>("/signalr");

            // Add a new middleware issuing access tokens.
            app.UseOpenIdConnectServer(options => {
                options.Provider = new AuthenticationProvider();
            });
        }
开发者ID:DovydasNavickas,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:52,代码来源:Startup.cs

示例4: Configure

        public void Configure(IApplicationBuilder app) {
            app.UseDefaultFiles();

            app.UseStaticFiles();

            // Add a new middleware validating access tokens.
            app.UseOAuthValidation(options => {
                options.Events = new OAuthValidationEvents {
                    // Note: for SignalR connections, the default Authorization header does not work,
                    // because the WebSockets JS API doesn't allow setting custom parameters.
                    // To work around this limitation, the access token is retrieved from the query string.
                    OnRetrieveToken = context => {
                        context.Token = context.Request.Query["access_token"];

                        return Task.FromResult(0);
                    }
                };
            });

            app.UseSignalR<SimpleConnection>("/signalr");

            // Add a new middleware issuing access tokens.
            app.UseOpenIdConnectServer(options => {
                options.Provider = new AuthorizationProvider();

                // Enable the token endpoint.
                options.TokenEndpointPath = "/connect/token";
                options.AllowInsecureHttp = true;

                // Register a new ephemeral key, that is discarded when the application
                // shuts down. Tokens signed using this key are automatically invalidated.
                // This method should only be used during development.
                options.SigningCredentials.AddEphemeralKey();

                // On production, using a X.509 certificate stored in the machine store is recommended.
                // You can generate a self-signed certificate using Pluralsight's self-cert utility:
                // https://s3.amazonaws.com/pluralsight-free/keith-brown/samples/SelfCert.zip
                //
                // options.SigningCredentials.AddCertificate("7D2A741FE34CC2C7369237A5F2078988E17A6A75");
            });
        }
开发者ID:aspnet-contrib,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:41,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app) {
            app.UseDeveloperExceptionPage();

            // Create a new branch where the registered middleware will be executed only for API calls.
            app.UseWhen(context => context.Request.Path.StartsWithSegments(new PathString("/api")), branch => {
                branch.UseOAuthValidation(new OAuthValidationOptions {
                    AutomaticAuthenticate = true,
                    AutomaticChallenge = true
                });

                // Alternatively, you can also use the introspection middleware.
                // Using it is recommended if your resource server is in a
                // different application/separated from the authorization server.
                // 
                // branch.UseOAuthIntrospection(new OAuthIntrospectionOptions {
                //     AutomaticAuthenticate = true,
                //     AutomaticChallenge = true,
                //     Authority = "http://localhost:54540/",
                //     Audiences = { "resource_server" },
                //     ClientId = "resource_server",
                //     ClientSecret = "875sqd4s5d748z78z7ds1ff8zz8814ff88ed8ea4z4zzd"
                // });
            });

            // Create a new branch where the registered middleware will be executed only for non API calls.
            app.UseWhen(context => !context.Request.Path.StartsWithSegments(new PathString("/api")), branch => {
                // Insert a new cookies middleware in the pipeline to store
                // the user identity returned by the external identity provider.
                branch.UseCookieAuthentication(new CookieAuthenticationOptions {
                    AutomaticAuthenticate = true,
                    AutomaticChallenge = true,
                    AuthenticationScheme = "ServerCookie",
                    CookieName = CookieAuthenticationDefaults.CookiePrefix + "ServerCookie",
                    ExpireTimeSpan = TimeSpan.FromMinutes(5),
                    LoginPath = new PathString("/signin"),
                    LogoutPath = new PathString("/signout")
                });

                branch.UseGoogleAuthentication(new GoogleOptions {
                    ClientId = "560027070069-37ldt4kfuohhu3m495hk2j4pjp92d382.apps.googleusercontent.com",
                    ClientSecret = "n2Q-GEw9RQjzcRbU3qhfTj8f"
                });

                branch.UseTwitterAuthentication(new TwitterOptions {
                    ConsumerKey = "6XaCTaLbMqfj6ww3zvZ5g",
                    ConsumerSecret = "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI"
                });
            });

            app.UseOpenIdConnectServer(options => {
                options.Provider = new AuthorizationProvider();

                // Enable the authorization, logout, token and userinfo endpoints.
                options.AuthorizationEndpointPath = "/connect/authorize";
                options.LogoutEndpointPath = "/connect/logout";
                options.TokenEndpointPath = "/connect/token";
                //options.UserinfoEndpointPath = "/connect/userinfo";

                // Note: if you don't explicitly register a signing key, one is automatically generated and
                // persisted on the disk. If the key cannot be persisted, an exception is thrown.
                // 
                // On production, using a X.509 certificate stored in the machine store is recommended.
                // You can generate a self-signed certificate using Pluralsight's self-cert utility:
                // https://s3.amazonaws.com/pluralsight-free/keith-brown/samples/SelfCert.zip
                // 
                // options.SigningCredentials.AddCertificate("7D2A741FE34CC2C7369237A5F2078988E17A6A75");
                // 
                // Alternatively, you can also store the certificate as an embedded .pfx resource
                // directly in this assembly or in a file published alongside this project:
                // 
                // options.SigningCredentials.AddCertificate(
                //     assembly: typeof(Startup).GetTypeInfo().Assembly,
                //     resource: "Backend.Certificate.pfx",
                //     password: "Owin.Security.OpenIdConnect.Server");

                // Note: see AuthorizationController.cs for more
                // information concerning ApplicationCanDisplayErrors.
                options.ApplicationCanDisplayErrors = true;
                options.AllowInsecureHttp = true;

                // Note: to override the default access token format and use JWT, assign AccessTokenHandler:
                // options.AccessTokenHandler = new JwtSecurityTokenHandler();
            });

            app.UseStaticFiles();

            app.UseMvc();

            app.UseWelcomePage();

            using (var context = new ApplicationContext(
                app.ApplicationServices.GetRequiredService<DbContextOptions<ApplicationContext>>())) {
                // Note: when using the introspection middleware, your resource server
                // MUST be registered as an OAuth2 client and have valid credentials.
                // 
                // database.Applications.Add(new Application {
                //     ApplicationID = "resource_server",
                //     DisplayName = "Main resource server",
                //     Secret = "875sqd4s5d748z78z7ds1ff8zz8814ff88ed8ea4z4zzd"
                // });
//.........这里部分代码省略.........
开发者ID:pierre-weceipt,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:101,代码来源:Startup.cs

示例6: Configure

        public void Configure(IApplicationBuilder app) {
            var factory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
            factory.AddConsole();

            app.UseIISPlatformHandler(options => {
                options.AuthenticationDescriptions.Clear();
            });

            app.UseStaticFiles();

            // Create a new branch where the registered middleware will be executed only for API calls.
            app.UseWhen(context => context.Request.Path.StartsWithSegments(new PathString("/api")), branch => {
                branch.UseJwtBearerAuthentication(options => {
                    options.AutomaticAuthenticate = true;
                    options.AutomaticChallenge = true;
                    options.RequireHttpsMetadata = false;

                    options.Audience = "http://localhost:54540/";
                    options.Authority = "http://localhost:54540/";
                });
            });

            // Create a new branch where the registered middleware will be executed only for non API calls.
            app.UseWhen(context => !context.Request.Path.StartsWithSegments(new PathString("/api")), branch => {
                // Insert a new cookies middleware in the pipeline to store
                // the user identity returned by the external identity provider.
                branch.UseCookieAuthentication(options => {
                    options.AutomaticAuthenticate = true;
                    options.AutomaticChallenge = true;
                    options.AuthenticationScheme = "ServerCookie";
                    options.CookieName = CookieAuthenticationDefaults.CookiePrefix + "ServerCookie";
                    options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
                    options.LoginPath = new PathString("/signin");
                });

                branch.UseGoogleAuthentication(options => {
                    options.ClientId = "560027070069-37ldt4kfuohhu3m495hk2j4pjp92d382.apps.googleusercontent.com";
                    options.ClientSecret = "n2Q-GEw9RQjzcRbU3qhfTj8f";
                });

                branch.UseTwitterAuthentication(options => {
                    options.ConsumerKey = "6XaCTaLbMqfj6ww3zvZ5g";
                    options.ConsumerSecret = "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI";
                });
            });

#if !DNXCORE50
            app.UseOwinAppBuilder(owin => {
                // Insert a new middleware responsible of setting the Content-Security-Policy header.
                // See https://nwebsec.codeplex.com/wikipage?title=Configuring%20Content%20Security%20Policy&referringTitle=NWebsec
                owin.UseCsp(options => options.DefaultSources(configuration => configuration.Self())
                                              .ImageSources(configuration => configuration.Self().CustomSources("data:"))
                                              .ScriptSources(configuration => configuration.UnsafeInline())
                                              .StyleSources(configuration => configuration.Self().UnsafeInline()));

                // Insert a new middleware responsible of setting the X-Content-Type-Options header.
                // See https://nwebsec.codeplex.com/wikipage?title=Configuring%20security%20headers&referringTitle=NWebsec
                owin.UseXContentTypeOptions();

                // Insert a new middleware responsible of setting the X-Frame-Options header.
                // See https://nwebsec.codeplex.com/wikipage?title=Configuring%20security%20headers&referringTitle=NWebsec
                owin.UseXfo(options => options.Deny());

                // Insert a new middleware responsible of setting the X-Xss-Protection header.
                // See https://nwebsec.codeplex.com/wikipage?title=Configuring%20security%20headers&referringTitle=NWebsec
                owin.UseXXssProtection(options => options.EnabledWithBlockMode());
            });
#endif

            app.UseOpenIdConnectServer(options => {
                options.Provider = new AuthorizationProvider();

                // Note: see AuthorizationController.cs for more
                // information concerning ApplicationCanDisplayErrors.
                options.ApplicationCanDisplayErrors = true;
                options.AllowInsecureHttp = true;

                // Note: by default, tokens are signed using dynamically-generated
                // RSA keys but you can also use your own certificate:
                // options.SigningCredentials.AddCertificate(certificate);
            });

            app.UseMvc();

            app.UseWelcomePage();

            using (var database = app.ApplicationServices.GetService<ApplicationContext>()) {
                database.Applications.Add(new Application {
                    ApplicationID = "myClient",
                    DisplayName = "My client application",
                    RedirectUri = "http://localhost:53507/signin-oidc",
                    LogoutRedirectUri = "http://localhost:53507/",
                    Secret = "secret_secret_secret"
                });

                database.SaveChanges();
            }
        }
开发者ID:QuatroCode,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:98,代码来源:Startup.cs

示例7: Configure

        public void Configure(IApplicationBuilder app, IRuntimeEnvironment env)
        {
            app.Map("/api", api =>
            {
                api.UseOAuthBearerAuthentication(options =>
                {
                    options.AutomaticAuthentication = true;
                    options.Authority = "http://localhost:35718/";
                    options.Audience = "http://localhost:35718/";
                });

                api.UseMvc();
            });

            app.UseOpenIdConnectServer(options =>
            {
                options.AuthenticationScheme = OpenIdConnectDefaults.AuthenticationScheme;

                // There's currently a bug in System.IdentityModel.Tokens that prevents using X509 certificates on Mono.
                // To work around this bug, a new in-memory RSA key is generated each time this app is started.
                // See https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/179
                if (string.Equals(env.RuntimeType, "Mono", StringComparison.OrdinalIgnoreCase))
                {
                    var rsaCryptoServiceProvider = new RSACryptoServiceProvider(2048);
                    var rsaParameters = rsaCryptoServiceProvider.ExportParameters(true);

                    options.UseKey(new RsaSecurityKey(rsaParameters));
                }
                else
                {
                    options.UseCertificate(typeof(Startup).GetTypeInfo().Assembly, "AureliaDemo.Certificate.pfx", "Owin.Security.OpenIdConnect.Server");
                }

                options.ApplicationCanDisplayErrors = true;
                options.AllowInsecureHttp = true;
                options.Issuer = new Uri("http://localhost:35718/");
                options.AuthorizationEndpointPath = PathString.Empty;

                options.Provider = new AuthorizationProvider();
            });

            app.UseDefaultFiles();
            app.UseStaticFiles();

            ApplicationDbOperations.InitializeIdentityDbAsync(app.ApplicationServices).Wait();
        }
开发者ID:SonOfSam,项目名称:Aurelia-Demo,代码行数:46,代码来源:Startup.cs

示例8: Configure

        //public Task rv(ReceivingTokenContext con)
        //{
        //    return Task.FromResult(true);
        //}
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            app.UseCors("AllowAllOrigins");
            app.UseIISPlatformHandler();
            app.UseDeveloperExceptionPage();
            app.UseDefaultFiles();
            app.UseStaticFiles();



            // Create a new branch where the registered middleware will be executed only for API calls.            

            //app.UseWhen(context => (context.Request.Path.StartsWithSegments(new PathString("/api")) 
            //    || context.Request.Path.StartsWithSegments(new PathString("/signalr"))) && 
            //    !context.Request.Path.StartsWithSegments(new PathString("/signalr/negotiate")) &&
            //    !context.Request.Path.StartsWithSegments(new PathString("/signalr/connect")) , branch =>
            //var path = context.Request.Path;


            //app.UseWhen(context => (context.Request.Path.StartsWithSegments(new PathString("/api"))
            //    || context.Request.Path.StartsWithSegments(new PathString("/signalr"))) && !(context.Request.Path.StartsWithSegments(new PathString("/signalr"))
            //    && context.Request.Path.ToString().Contains("abort")), branch =>
            app.UseWhen(context => context.Request.Path.StartsWithSegments(new PathString("/api"))
                || context.Request.Path.StartsWithSegments(new PathString("/signalr")), branch =>
            {
                branch.UseJwtBearerAuthentication(options =>
                {

                    options.AutomaticAuthenticate = true;
                    //options.AuthenticationScheme = 
                    options.AutomaticChallenge = true;
                    options.RequireHttpsMetadata = false;
                    options.TokenValidationParameters.ValidateLifetime = true;
                    options.TokenValidationParameters.ClockSkew = TimeSpan.Zero;
                    options.TokenValidationParameters.ValidAudiences = new[] { "http://localhost:10450/", "http://localhost:10377/" };
                    options.Authority = "http://localhost:10450/";
                    options.Events = new JwtBearerEvents()
                    {
                        OnReceivingToken = tokenContext =>
                        {
                            //return Task.FromResult(true);
                            // Note: when the token is missing from the query string,
                            // context.Token is null and the JWT bearer middleware will
                            // automatically try to retrieve it from the Authorization header.
                            var path = tokenContext.HttpContext.Request.Path;
                            var isSignalR = tokenContext.HttpContext.Request.Path.ToString().StartsWith("/signalr");
                            //var isSignalR = path.StartsWithSegments("/signalr") && !path.ToString().Contains("abort");
                            if (isSignalR)
                            {
                                tokenContext.Token = tokenContext.Request.Query["access_token"];
                            }

                            return Task.FromResult(0);
                        }

                    };
                });
            });

            // Note: visit https://docs.nwebsec.com/en/4.2/nwebsec/Configuring-csp.html for more information.
            app.UseCsp(options => options.DefaultSources(configuration => configuration.Self())
                                         .ImageSources(configuration => configuration.Self().CustomSources("data:"))
                                         .ScriptSources(configuration => configuration.UnsafeInline())
                                         .StyleSources(configuration => configuration.Self().UnsafeInline()));

            app.UseXContentTypeOptions();

            app.UseXfo(options => options.Deny());

            app.UseXXssProtection(options => options.EnabledWithBlockMode());

            app.UseOpenIdConnectServer(options =>
            {

                options.Provider = new AuthorizationProvider<ApplicationUser, Application>();

                // Note: see AuthorizationController.cs for more
                // information concerning ApplicationCanDisplayErrors.
                options.ApplicationCanDisplayErrors = true;
                options.AllowInsecureHttp = true;
                options.AuthorizationEndpointPath = PathString.Empty;
                //options.AuthorizationEndpointPath = "/auth";
                //options.ProfileEndpointPath = "/prof";
                options.TokenEndpointPath = "/token";
                //options.AccessTokenLifetime = new TimeSpan(10, 10, 10, 10);

                //options.IdentityTokenLifetime = new TimeSpan(0, 0, 3);
                //options.RefreshTokenLifetime = new TimeSpan(0, 0, 3);

                // Note: by default, tokens are signed using dynamically-generated
                // RSA keys but you can also use your own certificate:
                // options.SigningCredentials.AddCertificate(certificate);
            });
//.........这里部分代码省略.........
开发者ID:Stalso,项目名称:AspNetTemplate,代码行数:101,代码来源:Startup.cs

示例9: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment hostEnv, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            app.UseIISPlatformHandler();

            if (hostEnv.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("Error");
            }

            // Create a new branch where the registered middleware will be executed only for API calls.
            app.UseWhen(context => context.Request.Path.StartsWithSegments(new PathString("/api")), branch =>
            {
                branch.UseJwtBearerAuthentication(options =>
                {
                    options.AutomaticAuthenticate = true;
                    options.AutomaticChallenge = true;
                    options.RequireHttpsMetadata = false;

                    options.Audience = "http://localhost:54683/";
                    options.Authority = "http://localhost:54683/";
                });
            });

            // Create a new branch where the registered middleware will be executed only for non API calls.
            app.UseWhen(context => !context.Request.Path.StartsWithSegments(new PathString("/api")), branch =>
            {
                // Insert a new cookies middleware in the pipeline to store
                // the user identity returned by the external identity provider.
                branch.UseCookieAuthentication(options =>
                {
                    options.AutomaticAuthenticate = true;
                    options.AutomaticChallenge = true;
                    options.AuthenticationScheme = "ServerCookie";
                    options.CookieName = CookieAuthenticationDefaults.CookiePrefix + "ServerCookie";
                    options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
                    options.LoginPath = new PathString("/account/login");
                });

                branch.UseIdentity();
            });

            app.UseOpenIdConnectServer(options =>
            {
                options.Provider = new AuthorizationProvider();

                // Note: see AuthorizationController.cs for more
                // information concerning ApplicationCanDisplayErrors.
                options.ApplicationCanDisplayErrors = true;
                options.AllowInsecureHttp = true;

                // Note: by default, tokens are signed using dynamically-generated
                // RSA keys but you can also use your own certificate:
                // options.SigningCredentials.AddCertificate(certificate);
            });

            app.UseStaticFiles();

            app.UseMvc();

            app.UseWelcomePage();

            using (var database = app.ApplicationServices.GetService<ApplicationContext>())
            {
                database.Applications.Add(new Application
                {
                    ApplicationID = "myClient",
                    DisplayName = "My client application",
                    RedirectUri = "http://localhost:59872/signin-oidc",
                    LogoutRedirectUri = "http://localhost:59872/",
                    Secret = "secret_secret_secret"
                });

                database.SaveChanges();
            }
        }
开发者ID:Fosol,项目名称:Example.Oauth,代码行数:83,代码来源:Startup.cs

示例10: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
           

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            
            
            app.UseIISPlatformHandler();
   
            app.UseStaticFiles();
            app.UseCors("corsGlobalPolicy");

            //security


            app.UseJwtBearerAuthentication(options =>
            {
                options.AutomaticAuthenticate = true;
                options.Audience = "api";
                options.Authority = "http://localhost:62086";

                options.RequireHttpsMetadata = false;


 
            });

            // Add a new middleware issuing tokens.



            app.UseOpenIdConnectServer(options =>
            {
                options.AllowInsecureHttp = true;
                options.AuthorizationEndpointPath = PathString.Empty;
                options.TokenEndpointPath = "/login";
                var db = app.ApplicationServices.GetService<ICTX>();
                options.ApplicationCanDisplayErrors = true;
                options.Provider = new AuthProvider(db);
                options.Issuer = new Uri("http://localhost:62086");
                options.RefreshTokenLifetime = new TimeSpan(1, 0, 0, 0, 0);
                options.ProfileEndpointPath = new PathString("/profile");
                

            });





            app.UseMvc();
        }
开发者ID:tadmcclellan,项目名称:WebAPI,代码行数:54,代码来源:Startup.cs

示例11: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseOAuthValidation();
            app.UseCors(p => p.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin().AllowCredentials());
            app.UseOpenIdConnectServer(options => {
                // Create your own authorization provider by subclassing
                // the OpenIdConnectServerProvider base class.
                options.Provider = new AuthorizationProvider();
                options.IdentityTokenLifetime = TimeSpan.FromDays(1460);
                options.AccessTokenLifetime = TimeSpan.FromDays(1460);

                // Enable the authorization and token endpoints.
                options.AuthorizationEndpointPath = "/api/authorize";
                options.TokenEndpointPath = "/api/token";

                // During development, you can set AllowInsecureHttp
                // to true to disable the HTTPS requirement.

                //if (env.IsDevelopment())
                options.AllowInsecureHttp = true;

                var jwtSigningCert = new X509Certificate2(Path.Combine(env.ContentRootPath,"AuthSample.pfx"), Configuration["PfxPw"]);
                options.SigningCredentials.AddCertificate(jwtSigningCert);

                // Note: uncomment this line to issue JWT tokens.
                // options.AccessTokenHandler = new JwtSecurityTokenHandler();
            });

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            //if (env.IsDevelopment() || env.IsStaging())
            //   DbContextExtensions.Seed(app);

            app.UseApplicationInsightsRequestTelemetry();

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseMvc();
        }
开发者ID:hotdiggitydoddo,项目名称:sugarmama,代码行数:41,代码来源:Startup.cs


注:本文中的IApplicationBuilder.UseOpenIdConnectServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。