本文整理汇总了C#中IServiceCollection.AddDataProtection方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddDataProtection方法的具体用法?C# IServiceCollection.AddDataProtection怎么用?C# IServiceCollection.AddDataProtection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddDataProtection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection();
services.Configure<ExternalAuthenticationOptions>(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
}
示例2: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// DI bindings
new DependencyInjection().Bind(services);
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
services.AddDataProtection();
services.AddMvc();
}
示例3: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection();
services.AddMvc();
// I only put this here to keep things simple for people :)
services.AddWebApiConventions();
}
示例4: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// never persist key store to local directory, just for demo purposes
services.AddDataProtection()
.SetApplicationName("DataProtectionDemo")
.PersistKeysToFileSystem(new DirectoryInfo(_env.ContentRootPath));
//.ProtectKeysWithDpapi();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<OperationalContext>(o => o.UseSqlServer(Configuration["IdSvr3:ConnString:Identity_Operational"]))
.AddDbContext<ClientConfigurationContext>(o => o.UseSqlServer(Configuration["IdSvr3:ConnString:Identity_Client"]))
.AddDbContext<ScopeConfigurationContext>(o => o.UseSqlServer(Configuration["IdSvr3:ConnString:Identity_Scopes"]));
}
示例6: AddViewServices
// Internal for testing.
internal static void AddViewServices(IServiceCollection services)
{
services.AddDataProtection();
services.AddAntiforgery();
services.AddWebEncoders();
services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<MvcViewOptions>, MvcViewOptionsSetup>());
//
// View Engine and related infrastructure
//
// The provider is inexpensive to initialize and provides ViewEngines that may require request
// specific services.
services.TryAddScoped<ICompositeViewEngine, CompositeViewEngine>();
// Support for activating ViewDataDictionary
services.TryAddEnumerable(
ServiceDescriptor
.Transient<IControllerPropertyActivator, ViewDataDictionaryControllerPropertyActivator>());
//
// HTML Helper
//
services.TryAddTransient<IHtmlHelper, HtmlHelper>();
services.TryAddTransient(typeof(IHtmlHelper<>), typeof(HtmlHelper<>));
// DefaultHtmlGenerator is pretty much stateless but depends on IUrlHelper, which is scoped.
// Therefore it too is scoped.
services.TryAddScoped<IHtmlGenerator, DefaultHtmlGenerator>();
//
// JSON Helper
//
services.TryAddSingleton<IJsonHelper, JsonHelper>();
services.TryAdd(ServiceDescriptor.Singleton<JsonOutputFormatter>(serviceProvider =>
{
var options = serviceProvider.GetRequiredService<IOptions<MvcJsonOptions>>().Options;
return new JsonOutputFormatter(options.SerializerSettings);
}));
//
// View Components
//
// These do caching so they should stay singleton
services.TryAddSingleton<IViewComponentSelector, DefaultViewComponentSelector>();
services.TryAddSingleton<IViewComponentActivator, DefaultViewComponentActivator>();
services.TryAddSingleton<
IViewComponentDescriptorCollectionProvider,
DefaultViewComponentDescriptorCollectionProvider>();
services.TryAddTransient<IViewComponentDescriptorProvider, DefaultViewComponentDescriptorProvider>();
services.TryAddSingleton<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
services.TryAddTransient<IViewComponentHelper, DefaultViewComponentHelper>();
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
OnConfigureServices(services);
services.AddDataProtection();
services.AddIdentityServer(Options)
.AddInMemoryClients(Clients)
.AddInMemoryScopes(Scopes)
.AddInMemoryUsers(Users);
}
示例8: 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)
{
services.AddDataProtection();
services.AddScoped<IUserProfileRepository, UserProfileRepository>();
// Configure SQL connection string
services.AddEntityFramework().AddSqlServer().AddDbContext<TeammateOnlineContext>(options =>
{
options.UseSqlServer(Configuration.GetSection("Database:ConnectionString").Value);
});
}
示例9: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddTransient<IConfigurationRepository>(p => new FileConfigurationRepository("files", p.GetService<ILogger<FileConfigurationRepository>>()));
services.AddLogging();
services.AddDataProtection();
services.AddTransient<IAuthenticationService, AuthenticationService>();
services.AddTransient<IKeyGeneratorService, AuthenticationService>();
}
示例10: 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)
{
services.AddDataProtection();
//Set up CORS
var policy = new CorsPolicy();
policy.Headers.Add("*");
policy.Methods.Add("*");
policy.Origins.Add("*");
policy.SupportsCredentials = true;
services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));
}
示例11: ConfigureProductionServices
public void ConfigureProductionServices(IServiceCollection services)
{
ConfigureServices(services);
// register redis connection
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(Configuration.GetConnectionString("redis"));
services.AddSingleton(redis);
// register dataprotector
services.AddDataProtection(options =>
{
options.ApplicationDiscriminator = "dgo";
});
}
示例12: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
OnConfigureServices(services);
services.AddDataProtection();
Options.SigningCertificate = new X509Certificate2(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "idsrvtest.pfx"), "idsrv3test");
services.AddIdentityServer(Options)
.AddInMemoryClients(Clients)
.AddInMemoryScopes(Scopes)
.AddInMemoryUsers(Users);
}
示例13: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
var connection = Configuration["Production:SqliteConnectionString"];
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<MyIdentityDbContext>(options => options.UseSqlite(connection));
services.AddIdentity<MyUser, IdentityRole>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonLetterOrDigit = false;
options.Password.RequireUppercase = false;
options.Password.RequiredLength = 6;
})
.AddEntityFrameworkStores<MyIdentityDbContext>()
.AddDefaultTokenProviders();
services.AddDataProtection();
}
示例14: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// *** CHANGE THIS FOR PRODUCTION USE ***
// Here, we're generating a random key to sign tokens - obviously this means
// that each time the app is started the key will change, and multiple servers
// all have different keys. This should be changed to load a key from a file
// securely delivered to your application, controlled by configuration.
//
// See the RSAKeyUtils.GetKeyParameters method for an examle of loading from
// a JSON file.
//RSAParameters keyParams = RSAKeyUtils.GetRandomKey();
services.AddDataProtection();
services.ConfigureDataProtection(configure =>
{
// persist keys to a specific directory
configure.PersistKeysToFileSystem(new DirectoryInfo(@".\keys"));
// uncomment when doing this from different application
//configure.SetApplicationName("SameAppName");
});
var lServices = services.BuildServiceProvider();
tokenOptions = RSAKeyUtils.GetTokenOptions(lServices);
// Save the token options into an instance so they're accessible to the
// controller.
services.AddInstance<TokenAuthOptions>(tokenOptions);
// Enable the use of an [Authorize("Bearer")] attribute on methods and classes to protect.
services.AddAuthorization(auth =>
{
auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser().Build());
});
services.AddMvc();
}
示例15: ConfigureServices
// This method gets called by the runtime.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddWebEncoders();
services.AddDataProtection();
services.Configure<Auth0Settings>(Configuration.GetSection("Auth0"));
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.Configure<SharedAuthenticationOptions>(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
var settings = Configuration.Get<Auth0Settings>("Auth0");
services.UseAuth0(settings.Domain, settings.ClientId, settings.ClientSecret, settings.RedirectUri, notification =>
{
var identity = notification.AuthenticationTicket.Principal.Identity as ClaimsIdentity;
// Optional: add custom claims.
/*
if (identity.HasClaim(c => c.Type == "name"))
identity.AddClaim(new Claim(ClaimTypes.Name, identity.FindFirst("name").Value));
identity.AddClaim(new Claim("tenant", "12345"));
identity.AddClaim(new Claim("custom-claim", "custom-value"));
*/
// Optional: store tokens in the user object so you can retrieve those later.
/*
if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.AccessToken))
identity.AddClaim(new Claim("access_token", notification.TokenEndpointResponse.AccessToken));
if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.IdToken))
identity.AddClaim(new Claim("id_token", notification.TokenEndpointResponse.IdToken));
if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.RefreshToken))
identity.AddClaim(new Claim("refresh_token", notification.TokenEndpointResponse.RefreshToken));
*/
return Task.FromResult(true);
});
}