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


C# IServiceCollection.AddAuthentication方法代码示例

本文整理汇总了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>();
        }
开发者ID:HopeNB,项目名称:web,代码行数:32,代码来源:Startup.cs

示例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();
        }
开发者ID:Fosol,项目名称:Example.Oauth,代码行数:30,代码来源:Startup.cs

示例3: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddAuthentication(
         options => options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
     services.AddWebEncoders();
     services.AddMvc();
 }
开发者ID:mikeandersun,项目名称:experimental,代码行数:7,代码来源:Startup.cs

示例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();
        }
开发者ID:bensgroi,项目名称:PhotoGallery,代码行数:37,代码来源:Startup.cs

示例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();
 }
开发者ID:Chips100,项目名称:Dennika.WebApplication,代码行数:8,代码来源:Startup.cs

示例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();
        }
开发者ID:CWISoftware,项目名称:accounts,代码行数:32,代码来源:Startup.cs

示例7: ConfigureServices

        public void ConfigureServices(IServiceCollection services) {
            services.AddAuthentication(options => {
                options.SignInScheme = "ClientCookie";
            });

            services.AddMvc();
        }
开发者ID:pierre-weceipt,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:7,代码来源:Startup.cs

示例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();
        }
开发者ID:wmeints,项目名称:aspnet-demo,代码行数:26,代码来源:Startup.cs

示例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);
 }
开发者ID:gyantal,项目名称:SQLab,代码行数:9,代码来源:Startup.cs

示例10: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddAuthentication();
     services.Configure<ExternalAuthenticationOptions>(options =>
     {
         options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
     });
 }
开发者ID:james-wu,项目名称:Security,代码行数:8,代码来源:Startup.cs

示例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();
 }
开发者ID:JasonSoft,项目名称:single-sign-on,代码行数:10,代码来源:Startup.cs

示例12: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddAuthentication();
     services.AddAuthorization(options =>
     {
         options.AddPolicy("Authenticated", p => p.RequireAuthenticatedUser());
     });
 }
开发者ID:adammic,项目名称:aspnet5samples,代码行数:8,代码来源:Startup.cs

示例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();
        }
开发者ID:softwarejc,项目名称:angular2-aspmvc-core1-getting-started,代码行数:11,代码来源:Startup.cs

示例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();
 }
开发者ID:glennc,项目名称:GHUtils,代码行数:12,代码来源:Startup.cs


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