本文整理汇总了C#中IServiceCollection.AddAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddAuthentication方法的具体用法?C# IServiceCollection.AddAuthentication怎么用?C# IServiceCollection.AddAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.AddSingleton<IConfigurationRoot>(Configuration);
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddAuthentication(Configuration);
services.Configure<PayPalClientSettings>(Configuration.GetSection("PayPalClientSettings"));
services.AddSingleton<PayPalClient>();
services.AddLogging();
services.AddMvc();
// register document store
var store = DocumentStore.For(_ =>
{
_.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate;
_.Connection(Configuration.GetConnectionString("HopeNB"));
AsyncSessionFactory.Register(_);
});
store.Schema.ApplyAllConfiguredChangesToDatabase();
services.AddSingleton<IDocumentStore>(store);
AsyncSessionFactory.DocumentStore = store;
services.AddDistributedMemoryCache();
services.AddMultitenancy<Organization, CachingOrganizationResolver>();
}
示例2: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlServer()
.AddInMemoryDatabase()
.AddDbContext<ApplicationContext>(options => {
options.UseInMemoryDatabase();
})
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
//options.Cookies.ApplicationCookieAuthenticationScheme = "ServerCookie";
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.Configure<SharedAuthenticationOptions>(options => {
options.SignInScheme = "ServerCookie";
});
services.AddOpenIdConnectServer();
services.AddAuthentication();
services.AddCaching();
services.AddMvc();
}
示例3: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(
options => options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
services.AddWebEncoders();
services.AddMvc();
}
示例4: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<PhotoGalleryContext>(options =>
options.UseSqlServer(Configuration["Data:PhotoGalleryConnection:ConnectionString"]));
// Repositories
services.AddScoped<IPhotoRepository, PhotoRepository>();
services.AddScoped<IAlbumRepository, AlbumRepository>();
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IUserRoleRepository, UserRoleRepository>();
services.AddScoped<IRoleRepository, RoleRepository>();
services.AddScoped<ILoggingRepository, LoggingRepository>();
// Services
services.AddScoped<IMembershipService, MembershipService>();
services.AddScoped<IEncryptionService, EncryptionService>();
services.AddAuthentication();
// Policies
services.AddAuthorization(options =>
{
// inline policies
options.AddPolicy("AdminOnly", policy =>
{
policy.RequireClaim(ClaimTypes.Role, "Admin");
});
});
// Add MVC services to the services container.
services.AddMvc();
}
示例5: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
services.AddOptions();
services.Configure<ConfigOptions>(Configuration);
services.AddMvc();
}
示例6: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddCaching();
services.AddSession();
services.AddSwaggerGen();
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.Configure<MvcOptions>(options =>
{
//options.RespectBrowserAcceptHeader = true;
});
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<ApplicationDbContext>(options => { options.UseInMemoryDatabase(); });
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddUserStore<ApplicationUserStore<ApplicationUser>>()
.AddDefaultTokenProviders();
services.AddTransient<ApplicationUserManager>();
services.AddTransient<ApplicationSignInManager>();
services.AddTransient<IUserImageProvider, GravatarProvider>();
services.AddAuthentication();
// https://github.com/aspnet/Entropy/blob/dev/samples/Logging.Elm/Startup.cs
services.AddElm();
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services) {
services.AddAuthentication(options => {
options.SignInScheme = "ClientCookie";
});
services.AddMvc();
}
示例8: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
// OPTIONAL: Use a custom authorization handler to implement resource-based
// authorization in the application.
// services.AddTransient<IAuthorizationHandler,AdminUserHandler>();
// The authorization for the application is defined in a number of policies.
// Each policy defines what the user has to comply to in order to get access.
services.AddAuthorization(authorization => {
authorization.AddPolicy("Anonymous", policy => policy.RequireDelegate((context,requirement) => {
// When none of the identities are authenticated the user is anonymous.
// So the requirement was succesful.
if(context.User.Identities.All(identity => !identity.IsAuthenticated)) {
context.Succeed(requirement);
} else {
context.Fail();
}
}));
authorization.AddPolicy("Authenticated", policy => policy.RequireAuthenticatedUser());
});
services.AddMvc();
}
示例9: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddAuthentication(options => options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
services.AddMvc();
services.AddSingleton(_ => Utils.Configuration); // this is the proper DependenciInjection (DI) way of pushing it as a service to Controllers
services.AddSingleton(_ => WebAppGlobals);
}
示例10: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
}
示例11: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
}
示例12: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
services.AddAuthorization(options =>
{
options.AddPolicy("Authenticated", p => p.RequireAuthenticatedUser());
});
}
示例13: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//ActiveDirectory: Add the authentication middleware configuration
services.AddAuthentication(options => new ActiveDirectoryCookieOptions());
// Add framework services.
services.AddMvc();
}
开发者ID:OneBitSoftware,项目名称:Microsoft.AspNetCore.Authentication.ActiveDirectory,代码行数:9,代码来源:Startup.cs
示例14: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Configure authentication - who are you?
services.AddAuthentication();
// Configure authorization - what can you do?
services.AddAuthorization(CookieMonsterSecurity.Authorization);
services.AddMvc();
}
示例15: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
services.AddScoped(typeof(ScriptCollector));
services.AddScoped(typeof(GitHubService));
services.AddMvc();
}