本文整理汇总了C#中IApplicationBuilder.UseClaimsTransformation方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseClaimsTransformation方法的具体用法?C# IApplicationBuilder.UseClaimsTransformation怎么用?C# IApplicationBuilder.UseClaimsTransformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseClaimsTransformation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
{
app.UseIISPlatformHandler();
ApplicationConfiguration.SetContext("Elders.Pandora.Api");
foreach (var directory in new[] { Folders.Main, Folders.Users, Folders.Projects })
{
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
}
// Configure the HTTP request pipeline.
app.UseStaticFiles();
app.UseJwtBearerAuthentication(new JwtBearerOptions()
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
TokenValidationParameters = GoogleTokenValidationParameters.GetParameters()
});
app.UseClaimsTransformation(new ClaimsTransformationOptions() { Transformer = new ClaimsTransformer() });
// Add MVC to the request pipeline.
app.UseMvc();
}
示例2: 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();
}
示例3: 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?}");
});
}
示例4: Configure
public void Configure(IApplicationBuilder app, IOptions<AppSettings> settings)
{
// 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.AutomaticAuthentication = true;
options.AuthenticationScheme = "Cookies";
options.CookieName = "Cookies";
// options.CookieDomain = ".localhost.me";
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
options.LoginPath = new PathString("/login");
});
app.UseClaimsTransformation(options =>
{
// options.Transformer.Transform();
});
// Add static files
app.UseStaticFiles();
app.UseStatusCodePages();
// Choose an authentication type
app.Map("/login", signoutApp =>
{
signoutApp.Run(async context =>
{
await
context.Authentication.ChallengeAsync("Cookies");
return;
});
});
// Sign-out to remove the user cookie.
app.Map("/logout", signoutApp =>
{
signoutApp.Run(async context =>
{
await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
});
});
// Add MVC
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new {controller = "Home", action = "Index"}
);
});
}
示例5: 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.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?}");
});
}
示例6: 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.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Temp",
});
app.UseGoogleAuthentication(new GoogleOptions
{
AuthenticationScheme = "Google",
SignInScheme = "Temp",
ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com",
ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo"
});
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();
}
示例7: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage();
app.UseCookieAuthentication(CookieMonsterSecurity.AuthenticationOptions());
app.UseClaimsTransformation(user =>
{
if (user.Identity.IsAuthenticated)
{
var claim = new Claim("Dynamic Claim", "this claim was created using the middleware 'UseClaimsTransformation'");
user.Identities.First().AddClaims(new[] { claim });
}
return Task.FromResult(user);
});
app.UseMvc();
app.Run(async context =>
{
await context.Response.WriteAsync("Path not found: " + context.Request.Path);
});
}
示例8: 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();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
//serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
// .Database.Migrate();
}
}
catch { }
}
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();
app.UseClaimsTransformation(new Microsoft.AspNet.Authentication.ClaimsTransformationOptions { });
app.UseCookieAuthentication(options =>
{
options.LoginPath = "/account/login";
options.AccessDeniedPath = "/account/forbidden";
options.AuthenticationScheme = "Cookies";
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
});
// app.UseIdentity();
// To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例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, ILoggerFactory loggerFactory)
{
ApplicationConfiguration.SetContext("Elders.Pandora.Api");
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.AutomaticAuthenticate = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(50);
});
app.UseGoogleAuthentication(options =>
{
options.AutomaticChallenge = true;
options.ClientId = ApplicationConfiguration.Get("client_id");
options.ClientSecret = ApplicationConfiguration.Get("client_secret");
options.SignInScheme = "Cookies";
var scopes = ApplicationConfiguration.Get("scopes").Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
foreach (var scope in scopes)
{
options.Scope.Add(scope);
}
options.SaveTokensAsClaims = true;
options.Events = new OAuthEvents()
{
OnCreatingTicket = ctx =>
{
var tokens = ctx.TokenResponse;
ctx.Identity.AddClaim(new Claim("id_token", tokens.Response["id_token"].ToString()));
ctx.Identity.AddClaim(new Claim("avatar", ctx.User["image"]["url"].ToString()));
return Task.CompletedTask;
}
};
});
app.UseClaimsTransformation(new ClaimsTransformationOptions() { Transformer = new ClaimsTransformer() });
app.UseMvc(routes =>
{
routes.MapRoute(
name: "UsersRout",
template: "Users/{userId}",
defaults: new { controller = "Users", action = "Edit" }
);
routes.MapRoute(
name: "DefaultsRoute",
template: "Projects/{projectName}/{applicationName}/Clusters/Defaults",
defaults: new { controller = "Clusters", action = "Defaults" }
);
routes.MapRoute(
name: "AddMachineRoute",
template: "Projects/{projectName}/{applicationName}/{clusterName}/Machines/AddMachine",
defaults: new { controller = "Machines", action = "AddMachine" }
);
routes.MapRoute(
name: "AplicationRoute",
template: "Projects/{projectName}/{applicationName}/{clusterName}/Machines",
defaults: new { controller = "Machines", action = "Index" }
);
routes.MapRoute(
name: "MachineRoute",
template: "Projects/{projectName}/{applicationName}/{clusterName}/{machineName}",
defaults: new { controller = "Machines", action = "Machine" }
);
routes.MapRoute(
name: "ClustersRoute",
template: "Projects/{projectName}/{applicationName}/Clusters",
defaults: new { controller = "Clusters", action = "Index" }
);
routes.MapRoute(
name: "ApplicationDownloadJsonRoute",
template: "Projects/{projectName}/{applicationName}/DownloadJson",
defaults: new { controller = "Projects", action = "DownloadJson" }
//.........这里部分代码省略.........