本文整理汇总了C#中IApplicationBuilder.UseCookieAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseCookieAuthentication方法的具体用法?C# IApplicationBuilder.UseCookieAuthentication怎么用?C# IApplicationBuilder.UseCookieAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseCookieAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
app.UseCookieAuthentication(options =>
{
options.LoginPath = "/account/login";
options.AuthenticationScheme = "Cookies";
options.AutomaticAuthentication = true;
}, "main");
app.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "Temp";
options.AutomaticAuthentication = false;
}, "external");
app.UseGoogleAuthentication(options =>
{
options.ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
options.AuthenticationScheme = "Google";
options.SignInScheme = "Temp";
});
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
示例2: 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.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "Cookies";
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
options.LoginPath = new PathString("/account/login");
});
app.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "External";
});
app.UseGoogleAuthentication(options =>
{
options.AuthenticationScheme = "Google";
options.SignInScheme = "External";
options.ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
});
app.UseClaimsTransformation(user =>
{
if (user.Identity.IsAuthenticated)
{
user.Identities.First().AddClaim(
new Claim("now", DateTime.Now.ToString()));
}
return Task.FromResult(user);
});
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例3: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseIISPlatformHandler();
app.UseDeveloperExceptionPage();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
LoginPath = "/account/login",
AuthenticationScheme = "Cookies",
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Temp",
AutomaticAuthenticate = false
});
app.UseGoogleAuthentication(new GoogleOptions
{
ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com",
ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo",
AuthenticationScheme = "Google",
SignInScheme = "Temp"
});
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
示例4: Configure
public void Configure(IApplicationBuilder app)
{
app.UseCookieAuthentication(options =>
{
options.AutomaticAuthentication = true;
options.LoginPath = new PathString("/");
});
app.UseOAuthAuthentication("GitHub-AccessToken", options =>
{
options.ClientId = _configuration.Get("GitHub:ClientId");
options.ClientSecret = _configuration.Get("GitHub:Secret");
options.CallbackPath = new PathString("/signin-github");
options.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
options.TokenEndpoint = "https://github.com/login/oauth/access_token";
options.SaveTokensAsClaims = true;
options.Scope.Add("read:org");
options.Scope.Add("repo");
});
app.Use(async (context, next) =>
{
if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
{
await context.Authentication.ChallengeAsync("GitHub-AccessToken", new AuthenticationProperties() { RedirectUri = context.Request.Path.ToString() });
return;
}
await next();
});
app.UseMvcWithDefaultRoute();
}
示例5: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = Constants.MiddlewareScheme;
options.LoginPath = new PathString("/Account/Login/");
options.AccessDeniedPath = new PathString("/Account/Forbidden/");
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例6: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{
loggerfactory.AddConsole(LogLevel.Information);
app.UseCookieAuthentication(options =>
{
options.AutomaticAuthentication = true;
options.SessionStore = new MemoryCacheSessionStore();
});
app.Run(async context =>
{
if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
{
// Make a large identity
var claims = new List<Claim>(1001);
claims.Add(new Claim(ClaimTypes.Name, "bob"));
for (int i = 0; i < 1000; i++)
{
claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe"));
}
await context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme)));
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer");
return;
}
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello old timer");
});
}
示例7: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = Constants.MiddlewareScheme,
LoginPath = new PathString("/Account/Login/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例8: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies",
AutomaticAuthenticate = true,
AutomaticChallenge = true,
LoginPath = new PathString("/account/login")
});
app.UseClaimsTransformation(context =>
{
if (context.Principal.Identity.IsAuthenticated)
{
context.Principal.Identities.First().AddClaim(new Claim("now", DateTime.Now.ToString()));
}
return Task.FromResult(context.Principal);
});
app.UseMvcWithDefaultRoute();
}
示例9: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var configBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
Configuration = configBuilder.Build();
container.Options.DefaultScopedLifestyle = new AspNetRequestLifestyle();
app.UseSimpleInjectorAspNetRequestScoping(container);
InitializeContainer(app);
container.RegisterAspNetControllers(app);
container.Verify();
app.UseCookieAuthentication(p =>
{
p.AuthenticationScheme = "CustomSheme";
p.LoginPath = "/login";
p.AutomaticAuthenticate = true;
p.AutomaticChallenge = true;
});
app.UseStaticFiles();
app.UseIISPlatformHandler();
app.UseDeveloperExceptionPage();
app.UseMvc(ConfigureRoutes);
}
示例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, BlogContextDataSeed dataSeed)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIdentity();
//app.UseIISPlatformHandler();
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
app.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/Auth/Login");
});
app.UseStaticFiles();
app.UseMvc(config =>
{
config.MapRoute(
name: "Default",
template: "{controller}/{action}/{id?}",
defaults: new {controller = "App", action = "Index"});
});
_dataStartup.Configure(app, dataSeed);
}
示例11: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Trace);
loggerFactory.AddDebug(LogLevel.Trace);
app.UseDeveloperExceptionPage();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Temp",
AutomaticAuthenticate = false,
AutomaticChallenge = false
});
app.UseGoogleAuthentication(new GoogleOptions
{
AuthenticationScheme = "Google",
SignInScheme = "Temp",
ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com",
ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo"
});
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
示例12: 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
示例13: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{
loggerfactory.AddConsole(LogLevel.Information);
app.UseCookieAuthentication(options =>
{
options.AutomaticAuthenticate = true;
});
app.Run(async context =>
{
if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
{
var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") }, CookieAuthenticationDefaults.AuthenticationScheme));
await context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user);
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer");
return;
}
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello old timer");
});
}
示例14: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Verbose);
loggerFactory.AddDebug(LogLevel.Verbose);
app.UseDeveloperExceptionPage();
app.UseIISPlatformHandler();
app.UseIdentityServer();
app.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "External";
});
app.UseGoogleAuthentication(options =>
{
options.AuthenticationScheme = "Google";
options.SignInScheme = "External";
options.ClientId = Configuration["GoogleIdentityProvider:ClientId"];
options.ClientSecret = Configuration["GoogleIdentityProvider:ClientSecret"];
options.CallbackPath = new PathString("/googlecallback");
});
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
示例15: 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");
});
}