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


C# IApplicationBuilder.UseOpenIdConnectAuthentication方法代码示例

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


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

示例1: 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)
        {
            // Add the console logger.
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));

            // Configure error handling middleware.
            app.UseExceptionHandler("/Home/Error");

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Configure the OWIN pipeline to use cookie auth.
            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            // Configure the OWIN pipeline to use OpenID Connect auth.
            app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
            {
                ClientId = Configuration["AzureAD:ClientId"],
                Authority = String.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAd:Tenant"]),
                ResponseType = OpenIdConnectResponseType.IdToken,
                PostLogoutRedirectUri = Configuration["AzureAd:PostLogoutRedirectUri"],
                Events = new OpenIdConnectEvents
                {
                    OnRemoteFailure = OnAuthenticationFailed,
                }
            });

            // Configure MVC routes
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:joergjo,项目名称:active-directory-dotnet-webapp-openidconnect-aspnetcore,代码行数:36,代码来源:Startup.cs

示例2: Config

        public static void Config(IApplicationBuilder app)
        {
            OpenIdConnectEvents events = null;
            app.UseOpenIdConnectAuthentication(options =>
            {
                options.AuthenticationScheme = "Oidc";
                options.AutomaticAuthenticate = false;
                options.AutomaticChallenge = true;
                options.SignInScheme = "Cookies"; // Middle-ware to persist user in a cookie

                options.Authority = Constants.Authority; // Identity Server
                options.ClientId = Constants.ClientId; // This application must be registered in identity server with this id
                options.ResponseType = "code id_token";
                options.GetClaimsFromUserInfoEndpoint = true;

                options.Scope.Add("offline_access"); // this scope is needed to get the refresh token
                options.Scope.Add("role"); // a demo scope that contains a claim with the same name "role"
                options.Scope.Add("tickets_api"); // this scope is needed to access the resource API

                // Used to register events later
                events = options.Events as OpenIdConnectEvents;
            });

            if (events != null) events.OnAuthorizationCodeReceived = OnAuthorizationCodeReceived;
        }
开发者ID:softwarejc,项目名称:angular2-aspmvc-core1-getting-started,代码行数:25,代码来源:MyOpenIdConnect.cs

示例3: Configure

        public void Configure(IApplicationBuilder app)
        {
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            app.UseIISPlatformHandler();

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "Cookies";
                options.AutomaticAuthenticate = true;
            });

            app.UseOpenIdConnectAuthentication(options =>
            {
                options.AutomaticChallenge = true;
                options.AuthenticationScheme = "Oidc";
                options.SignInScheme = "Cookies";

                options.Authority = "http://localhost:18942/";
                options.RequireHttpsMetadata = false;

                options.ClientId = "mvc6";
                options.ResponseType = "id_token token";

                options.Scope.Add("openid");
                options.Scope.Add("email");
                options.Scope.Add("api1");
            });

            app.UseDeveloperExceptionPage();
            app.UseMvcWithDefaultRoute();
        }
开发者ID:RobGibbens,项目名称:IdentityServer3.Samples,代码行数:32,代码来源:Startup.cs

示例4: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
        {
            loggerfactory.AddConsole(LogLevel.Information);

            app.UseIISPlatformHandler();

            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthenticate = true;
            });

            app.UseOpenIdConnectAuthentication(options =>
            {
                options.ClientId = "63a87a83-64b9-4ac1-b2c5-092126f8474f";
                options.ClientSecret = "Yse2iP7tO1Azq0iDajNisMaTSnIDv+FXmAsFuXr+Cy8="; // for code flow
                options.Authority = "https://login.windows.net/tratcheroutlook.onmicrosoft.com";
                options.ResponseType = OpenIdConnectResponseTypes.Code;
                options.GetClaimsFromUserInfoEndpoint = true;
            });

            app.Run(async context =>
            {
                if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
                {
                    await context.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });

                    context.Response.ContentType = "text/plain";
                    await context.Response.WriteAsync("Hello First timer");
                    return;
                }

                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Hello Authenticated User");
            });
        }
开发者ID:leloulight,项目名称:Security,代码行数:35,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            app.UseDeveloperExceptionPage();
            app.UseStaticFiles();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Cookies",
                AutomaticAuthenticate = true
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
            {
                AuthenticationScheme = "oidc",
                SignInScheme = "Cookies",

                Authority = "https://demo.identityserver.io",
                PostLogoutRedirectUri = "http://localhost:3308/",
                ClientId = "hybrid",
                ClientSecret = "secret",
                ResponseType = "code id_token",
                GetClaimsFromUserInfoEndpoint = true,
                SaveTokens = true
            });

            app.UseMvcWithDefaultRoute();
        }
开发者ID:ReinhardHsu,项目名称:AspNetCoreSecuritySamples,代码行数:32,代码来源:Startup.cs

示例6: ConfigureAuthentication

        public void ConfigureAuthentication(IApplicationBuilder app, IOptions<AzureAdSettings> azureADSettings, IServiceProvider serviceProvider)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AutomaticAuthenticate = true
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
            {
                AuthenticationScheme = AuthenticationConstants.OpenIdConnectAzureAdB2CAuthenticationScheme,
                AutomaticChallenge = true,
                ClientId = azureADSettings.Value.ClientId,
                Authority = azureADSettings.Value.Authority,
                ResponseType = OpenIdConnectResponseType.IdToken,
                PostLogoutRedirectUri = azureADSettings.Value.PostLogoutRedirectUri,
                Events = new OpenIdConnectEvents
                {
                    OnAuthenticationFailed = OnAuthenticationFailed,
                    //  OnAuthorizationCodeReceived = OnAuthorizationCodeReceived,
                    OnRedirectToIdentityProvider = OnRedirectToIdentityProvider,
                    OnRedirectToIdentityProviderForSignOut = OnRedirectToIdentityProviderForSignOut
                },

                // The PolicyConfigurationManager takes care of getting the correct Azure AD authentication 
                // endpoints from the OpenID Connect metadata endpoint.  It is included in the Authentication folder. 
                ConfigurationManager = serviceProvider.GetRequiredService<PolicyConfigurationManager>(),
                SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme

            });
        }
开发者ID:pherbel,项目名称:AzureAd-b2c-aspnet5,代码行数:30,代码来源:Startup.Auth.cs

示例7: ConfigureAuth

        public void ConfigureAuth(IApplicationBuilder app)
        {
            // Populate AzureAd Configuration Values
            Authority = String.Format(Configuration.Get("AzureAd:AadInstance"), Configuration.Get("AzureAd:Tenant"));
            ClientId = Configuration.Get("AzureAd:ClientId");
            AppKey = Configuration.Get("AzureAd:AppKey");
            TodoListResourceId = Configuration.Get("AzureAd:TodoListResourceId");
            TodoListBaseAddress = Configuration.Get("AzureAd:TodoListBaseAddress");
            GraphResourceId = Configuration.Get("AzureAd:GraphResourceId");

            // Configure the Session Middleware, Used for Storing Tokens
            app.UseSession();

            // Configure OpenId Connect Authentication Middleware
            app.UseCookieAuthentication(options => { });
            app.UseOpenIdConnectAuthentication(options =>
            {
                options.ClientId = Configuration.Get("AzureAd:ClientId");
                options.Authority = Authority;
                options.PostLogoutRedirectUri = Configuration.Get("AzureAd:PostLogoutRedirectUri");
                options.Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                    AuthenticationFailed = OnAuthenticationFailed
                };
            });
        }
开发者ID:vansonvinhuni,项目名称:active-directory-dotnet-webapp-webapi-openidconnect-aspnet5,代码行数:27,代码来源:Startup.Auth.cs

示例8: Configure

        public void Configure(IApplicationBuilder app)
        {
            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthentication = true;
            });

            app.UseOpenIdConnectAuthentication(options =>
                {
                    options.ClientId = "fe78e0b4-6fe7-47e6-812c-fb75cee266a4";
                    options.Authority = "https://login.windows.net/cyrano.onmicrosoft.com";
                    options.RedirectUri = "http://localhost:42023";
                });

            app.Run(async context =>
            {
                if (context.User == null || !context.User.Identity.IsAuthenticated)
                {
                    context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme);

                    context.Response.ContentType = "text/plain";
                    await context.Response.WriteAsync("Hello First timer");
                    return;
                }

                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Hello Authenticated User");
            });


        }
开发者ID:SacmaIslerOfisi,项目名称:Security,代码行数:31,代码来源:Startup.cs

示例9: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
        {
            loggerfactory.AddConsole(LogLevel.Information);

            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthentication = true;
            });

            app.UseOpenIdConnectAuthentication(options =>
                {
                    options.ClientId = "fe78e0b4-6fe7-47e6-812c-fb75cee266a4";
                    options.Authority = "https://login.windows.net/cyrano.onmicrosoft.com";
                    options.RedirectUri = "http://localhost:42023";
                });

            app.Run(async context =>
            {
                if (string.IsNullOrEmpty(context.User.Identity.Name))
                {
                    context.Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });

                    context.Response.ContentType = "text/plain";
                    await context.Response.WriteAsync("Hello First timer");
                    return;
                }

                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Hello Authenticated User");
            });


        }
开发者ID:james-wu,项目名称:Security,代码行数:33,代码来源:Startup.cs

示例10: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment hostEnv, ILoggerFactory loggerFactory)
        {
            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();


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

            loggerFactory.MinimumLevel = LogLevel.Error;
            loggerFactory.AddConsole();

            // Insert a new cookies middleware in the pipeline to store the user
            // identity after he has been redirected from the identity provider.
            app.UseCookieAuthentication(options => {
                options.AutomaticAuthenticate = true;
                options.AutomaticChallenge = true;
                options.AuthenticationScheme = "ClientCookie";
                options.CookieName = CookieAuthenticationDefaults.CookiePrefix + "ClientCookie";
                options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
                options.LoginPath = new PathString("/signin");
            });

            app.UseOpenIdConnectAuthentication(options => {
                options.AuthenticationScheme = OpenIdConnectDefaults.AuthenticationScheme;
                options.RequireHttpsMetadata = false;

                // Note: these settings must match the application details
                // inserted in the database at the server level.
                options.ClientId = "myClient";
                options.ClientSecret = "secret_secret_secret";
                options.PostLogoutRedirectUri = "http://localhost:59872/";

                // Use the authorization code flow.
                options.ResponseType = OpenIdConnectResponseTypes.Code;

                // Note: setting the Authority allows the OIDC client middleware to automatically
                // retrieve the identity provider's configuration and spare you from setting
                // the different endpoints URIs or the token validation parameters explicitly.
                options.Authority = "http://localhost:54683/";

                // Note: the resource property represents the different endpoints the
                // access token should be issued for (values must be space-delimited).
                options.Resource = "http://localhost:54683/";
            });

            app.UseStaticFiles();

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

示例11: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIISPlatformHandler();
            app.UseStaticFiles();

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "cookies";
                options.AutomaticAuthenticate = true;
            });

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            app.UseOpenIdConnectAuthentication(options =>
            {
                options.AuthenticationScheme = "oidc";
                options.SignInScheme = "cookies";
                options.AutomaticChallenge = true;

                options.Authority = Clients.Constants.BaseAddress;
                options.RequireHttpsMetadata = false;

                options.ClientId = "mvc_implicit";
                options.ResponseType = "id_token token";
                options.SaveTokensAsClaims = true;

                options.Scope.Add("profile");
                options.Scope.Add("email");
                options.Scope.Add("roles");
                options.Scope.Add("api1");

                options.TokenValidationParameters.NameClaimType = "name";
                options.TokenValidationParameters.RoleClaimType = "role";
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:jvanrhyn,项目名称:IdentityServer4.Samples,代码行数:54,代码来源:Startup.cs

示例12: Configure

        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
        {
            // Configure the HTTP request pipeline.
            // Add the console logger.
            loggerfactory.AddConsole();

            // Add the following to the request pipeline only in development environment.
            if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
            {
                app.UseErrorPage();
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Configure the OWIN Pipeline to use Cookie Authentication
            app.UseCookieAuthentication(options =>
            {
                // By default, all middleware are passive/not automatic. Making cookie middleware automatic so that it acts on all the messages.
                options.AutomaticAuthentication = true;

            });

            // Configure the OWIN Pipeline to use OpenId Connect Authentication
            app.UseOpenIdConnectAuthentication(options =>
            {
                options.ClientId = Configuration.Get("AzureAd:ClientId");
                options.Authority = String.Format(Configuration.Get("AzureAd:AadInstance"), Configuration.Get("AzureAd:Tenant"));
                options.PostLogoutRedirectUri = Configuration.Get("AzureAd:PostLogoutRedirectUri");
                options.Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthenticationFailed = OnAuthenticationFailed,
                };
            });

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                // Uncomment the following line to add a route for porting Web API 2 controllers.
                // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
            });
        }
开发者ID:ForestZheng,项目名称:WebApp-OpenIdConnect-AspNet5,代码行数:55,代码来源:Startup.cs

示例13: Configure

        public void Configure(IApplicationBuilder app)
        {
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "Cookies";
                options.AutomaticAuthentication = true;
            });

            var authority = Configuration["IDP_AUTHORITY"] ?? "http://localhost:44002";
            var audience = $"{authority}/resources";
            var redirectUri = Configuration["REDIRECT_URI"] ?? "http://localhost:2221/";
            app.UseOpenIdConnectAuthentication(options =>
            {
                options.Authority = authority;
                options.ClientId = "mvc6";
                options.ResponseType = "id_token token";
                options.Scope = "openid email profile testapi";
                options.RedirectUri = redirectUri;
                options.SignInScheme = "Cookies";
                options.AutomaticAuthentication = true;

                options.Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = n =>
                        {
                    var incoming = n.AuthenticationTicket.Principal;

                        // create application identity
                        var id = new ClaimsIdentity("application", "given_name", "role");
                    id.AddClaim(incoming.FindFirst("sub"));
                    id.AddClaim(incoming.FindFirst("email"));
                    id.AddClaim(incoming.FindFirst("email_verified"));
                    id.AddClaim(incoming.FindFirst("given_name"));
                    id.AddClaim(incoming.FindFirst("family_name"));
                    id.AddClaim(new Claim("token", n.ProtocolMessage.AccessToken));

                    n.AuthenticationTicket = new AuthenticationTicket(
                        new ClaimsPrincipal(id),
                        n.AuthenticationTicket.Properties,
                        n.AuthenticationTicket.AuthenticationScheme);

                        // this skips nonce checking & cleanup 
                        // see https://github.com/aspnet/Security/issues/372
                        n.HandleResponse();
                    return Task.FromResult(0);
                }
                };
            });

            app.UseMvcWithDefaultRoute();
        }
开发者ID:mequanta,项目名称:Janitor-old,代码行数:53,代码来源:Startup.cs

示例14: 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();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIISPlatformHandler();

            app.UseStaticFiles();

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "Cookies";
                options.AutomaticAuthenticate = true;
            });

            app.UseOpenIdConnectAuthentication(options =>
            {
                options.AutomaticChallenge = true;
                options.AuthenticationScheme = "Oidc";
                options.SignInScheme = "Cookies";

                options.Authority = "http://localhost:50000";
                options.RequireHttpsMetadata = false;

                options.ClientId = "sampleMVC";
                options.ResponseType = "id_token token";

                options.Scope.Add("openid");
                options.Scope.Add("email");
                options.Scope.Add("sample_api");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:Junicus,项目名称:Sample2020,代码行数:50,代码来源:Startup.cs

示例15: 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.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIISPlatformHandler();

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthenticate = true;
            });

            app.UseOpenIdConnectAuthentication(options =>
            {
                options.AutomaticChallenge = true;
                options.ClientId = Configuration["Authentication:AzureAd:ClientId"];
                options.Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"];
                options.PostLogoutRedirectUri = Configuration["Authentication:AzureAd:PostLogoutRedirectUri"];
                options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:Nepomuceno,项目名称:emergencies,代码行数:45,代码来源:Startup.cs


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