本文整理汇总了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?}");
});
}
示例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;
}
示例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();
}
示例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");
});
}
示例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();
}
示例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
});
}
示例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");
});
}
示例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");
});
}
示例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();
}
示例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?}");
});
}
示例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?}");
});
}
示例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();
}
示例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?}");
});
}
示例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?}");
});
}