本文整理汇总了C#中IAppBuilder.GetDataProtectionProvider方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.GetDataProtectionProvider方法的具体用法?C# IAppBuilder.GetDataProtectionProvider怎么用?C# IAppBuilder.GetDataProtectionProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.GetDataProtectionProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
DataProtectionProvider = app.GetDataProtectionProvider();
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<ApplicationUserManager>());
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
app.UseAbp();
DataProtectionProvider = app.GetDataProtectionProvider();
app.UseOAuthBearerAuthentication(AccountController.OAuthBearerOptions);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
if (IsTrue("ExternalAuth.Facebook.IsEnabled"))
{
app.UseFacebookAuthentication(CreateFacebookAuthOptions());
}
if (IsTrue("ExternalAuth.Twitter.IsEnabled"))
{
app.UseTwitterAuthentication(CreateTwitterAuthOptions());
}
if (IsTrue("ExternalAuth.Google.IsEnabled"))
{
app.UseGoogleAuthentication(CreateGoogleAuthOptions());
}
app.MapSignalR();
}
示例3: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
DataProtectionProvider = app.GetDataProtectionProvider();
// Configure the db context and user manager to use a single instance per request
//app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(CreateKernel);
app.UseNinjectMiddleware(CreateKernel);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AccessTokenFormat = new HunterJwtFormat("http://localhost:53147/"),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
//app.UseOAuthBearerTokens(OAuthOptions);
app.UseOAuthAuthorizationServer(OAuthOptions);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseLinkedInAuthentication(
// "<YOUR API KEY>",
// "<YOUR SECRET KEY>"
// );
}
示例4: Configuration
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login")
});
DataProtectionProvider = app.GetDataProtectionProvider();
//HttpConfiguration config = new HttpConfiguration();
//config.MapHttpAttributeRoutes();
////config.Routes.MapHttpRoute(
//// name: "DefaultApi",
//// routeTemplate: "api/{controller}/{id}",
//// defaults: new { id = RouteParameter.Optional }
////);
//app.UseWebApi(config);
ImageResizer.Configuration.Config.Current.Pipeline.RewriteDefaults +=
delegate(IHttpModule m, HttpContext c, ImageResizer.Configuration.IUrlEventArgs args)
{
if (args.VirtualPath.IndexOf("/images/", StringComparison.OrdinalIgnoreCase) > -1)
args.QueryString["404"] = "~/images/404.png";
};
}
示例5: RegisterIdentity
private static void RegisterIdentity(IAppBuilder app, ContainerBuilder builder)
{
builder.RegisterType<UserStore<User>>()
.As<IUserStore<User, string>>()
.As<IUserStore<User>>()
.InstancePerLifetimeScope();
builder.RegisterType<UserManager<User, string>>()
.AsSelf()
.InstancePerRequest();
builder.RegisterType<UserManager<User>>()
.AsSelf()
.InstancePerRequest();
builder.RegisterType<SignInManager<User, string>>()
.AsSelf()
.InstancePerRequest();
builder.Register(c => HttpContext.Current.GetOwinContext().Authentication)
.AsImplementedInterfaces()
.InstancePerRequest();
builder.Register<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication)
.InstancePerRequest();
builder.Register<IDataProtectionProvider>(c => app.GetDataProtectionProvider())
.InstancePerRequest();
}
示例6: Configuration
public void Configuration(IAppBuilder app)
{
DataProtectionProvider = app.GetDataProtectionProvider();
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<MendotaContext>());
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<MendotaUserManager>());
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<MendotaSignInManager>());
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieHttpOnly = true,
CookieName = "Mendota",
ExpireTimeSpan = TimeSpan.FromDays(14),
LoginPath = new PathString("/Account/Login"),
LogoutPath = new PathString("/Account/Logout"),
ReturnUrlParameter = "ReturnUrl",
SlidingExpiration = true,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<MendotaUserManager, User, int>(
validateInterval: TimeSpan.FromMinutes(2),
regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
getUserIdCallback: (id) => (id.GetUserId<int>()))
}
});
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(10));
}
示例7: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
// REGISTER DEPENDENCIES
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerRequest();
builder.Register<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register<IDataProtectionProvider>(c => app.GetDataProtectionProvider()).InstancePerRequest();
// REGISTER CONTROLLERS SO DEPENDENCIES ARE CONSTRUCTOR INJECTED
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// BUILD THE CONTAINER
var container = builder.Build();
// REPLACE THE MVC DEPENDENCY RESOLVER WITH AUTOFAC
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// REGISTER WITH OWIN
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app);
}
示例8: Configuration
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
//app.CreateDataProtector("ASP.NET Identity");
// Configure OAuth
AuthConfig.ConfigureOAuthTokenGeneration(app);
// Configure Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.UseWebApi(config);
IDataProtectionProvider pro = app.GetDataProtectionProvider();
Console.WriteLine("Started");
}
示例9: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
/// <summary>
/// Configures the authentication used by Veil
/// </summary>
/// <param name="app">
/// The <see cref="IAppBuilder"/> to configure
/// </param>
public void ConfigureAuth(IAppBuilder app)
{
// Setup Unity to Configure IDataProtectionProvider for the VeilUserManager constructor
UnityConfig.GetConfiguredContainer().RegisterInstance(app.GetDataProtectionProvider());
IGuidUserIdGetter idGetter = UnityConfig.GetConfiguredContainer().Resolve<IGuidUserIdGetter>();
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ReturnUrlParameter = "returnUrl",
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity =
SecurityStampValidator.OnValidateIdentity<VeilUserManager, User, Guid>(
validateInterval: TimeSpan.FromMinutes(10),
regenerateIdentityCallback:
(manager, user) => user.GenerateUserIdentityAsync(manager),
getUserIdCallback: identity => idGetter.GetUserId(identity))
}
});
}
示例10: Register
public static void Register(IAppBuilder app, HttpConfiguration config)
{
var aspNetIdentityAssembly = typeof(IMarkerAspNetIdentityInterface).Assembly;
var cornhouseCoreAssembly = typeof (IMarkerCornhouseCoreInterface).Assembly;
var executingAssembly = Assembly.GetExecutingAssembly();
var builder = new ContainerBuilder();
builder.Register(c => InitializeRavenDb.Initialize(aspNetIdentityAssembly)).As<IDocumentStore>().InstancePerLifetimeScope();
builder.Register(c => c.Resolve<IDocumentStore>().OpenAsyncSession()).As<IAsyncDocumentSession>().InstancePerRequest();
builder.Register(c => HttpContext.Current.User).InstancePerRequest();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationRoleManager>().AsSelf().InstancePerRequest();
builder.RegisterType<RavenUserStore>().AsSelf().InstancePerRequest();
builder.RegisterType<RavenRoleStore>().AsSelf().InstancePerRequest();
builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest();
builder.RegisterApiControllers(executingAssembly);
builder.RegisterApiControllers(aspNetIdentityAssembly);
builder.RegisterAssemblyTypes(executingAssembly).AsImplementedInterfaces().InstancePerRequest();
builder.RegisterAssemblyTypes(aspNetIdentityAssembly).AsImplementedInterfaces().InstancePerRequest();
builder.RegisterAssemblyTypes(cornhouseCoreAssembly).AsImplementedInterfaces().InstancePerRequest();
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
app.UseAutofacMiddleware(container);
app.UseAutofacWebApi(config);
}
示例11: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
var assemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray();
builder.RegisterType<Entities>().As<IDbContext>().InstancePerLifetimeScope();
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerLifetimeScope();
builder.RegisterAssemblyTypes(typeof(IRepository<>).Assembly).AsClosedTypesOf(typeof(IRepository<>)).InstancePerRequest();
builder.RegisterAssemblyTypes(ServiceAssembly).Where(type => typeof(ServiceBase).IsAssignableFrom(type) && !type.IsAbstract).AsImplementedInterfaces().InstancePerRequest();
builder.RegisterAssemblyTypes(MapperAssembly).Where(type => typeof(MapperBase).IsAssignableFrom(type) && !type.IsAbstract).AsImplementedInterfaces().InstancePerRequest();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerRequest();
builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole, string>>().InstancePerRequest();
builder.RegisterType<ApplicationRoleManager>().AsSelf().InstancePerRequest();
builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest();
builder.RegisterModule(new LoggingModule());
builder.RegisterControllers(assemblies);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app);
}
示例12: ConfigAutofac
private void ConfigAutofac(IAppBuilder app)
{
var builder = new ContainerBuilder();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerRequest();
builder.RegisterType<DbFactory>().As<IDbFactory>().InstancePerRequest();
builder.RegisterType<ShopThanhDbContext>().AsSelf().InstancePerRequest();
//ASP Identity
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerRequest();
builder.Register(n => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register(n => app.GetDataProtectionProvider()).InstancePerRequest();
//Reponsitories
builder.RegisterAssemblyTypes(typeof(PostCategoryRepository).Assembly)
.Where(n => n.Name.EndsWith("Repository"))
.AsImplementedInterfaces().InstancePerRequest();
//Services
builder.RegisterAssemblyTypes(typeof(PostCategoryService).Assembly)
.Where(n => n.Name.EndsWith("Service"))
.AsImplementedInterfaces().InstancePerRequest();
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
示例13: RegisterDependancies
public static IComponentContext RegisterDependancies(IAppBuilder app)
{
var builder = new ContainerBuilder();
// REGISTER DEPENDENCIES
builder.RegisterType<ApplicationDbContext>().As<DbContext>();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>();
builder.RegisterType<ApplicationUserManager>().AsSelf();
builder.RegisterType<ApplicationSignInManager>().AsSelf();
builder.Register<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication);
builder.Register<IDataProtectionProvider>(c => app.GetDataProtectionProvider());
// register mvc controllers
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// register webapi controller
builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
builder.RegisterGeneric(typeof(DataRepository<>)).As(typeof(IDataRepository<>));
var container = builder.Build();
// replace mvc dependancy resolver with autofac
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// replace webapi dependancy resolver with autofac
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
return container;
}
示例14: Configuration
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext<DbContext>(() => DependencyResolver.Current.GetService<DbContext>());
app.CreatePerOwinContext<UserManager<User, int>>(() => DependencyResolver.Current.GetService<UserManager<User, int>>());
app.CreatePerOwinContext<SignInManager<User, int>>(() => DependencyResolver.Current.GetService<SignInManager<User, int>>());
DataProtectionProvider = app.GetDataProtectionProvider();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieHttpOnly = true,
CookieName = "Badger",
ExpireTimeSpan = TimeSpan.FromDays(30),
LoginPath = new PathString("/Account/SignIn"),
LogoutPath = new PathString("/Account/SignOut"),
ReturnUrlParameter = "ReturnUrl",
SlidingExpiration = true,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager<User,int>, User, int>(
validateInterval: TimeSpan.FromMinutes(1),
regenerateIdentityCallback: (manager, user) =>
user.GenerateUserIdentityAsync(manager),
getUserIdCallback: (id) => (id.GetUserId<int>()))
}
});
}
示例15: ConfigureAuth
private static void ConfigureAuth(IAppBuilder appBuilder)
{
const int twoWeeks = 14;
ProjectObjectFactory.Container.Configure(config => config.For<IDataProtectionProvider>()
.HybridHttpOrThreadLocalScoped()
.Use(() => appBuilder.GetDataProtectionProvider()));
appBuilder.CreatePerOwinContext(
() =>ProjectObjectFactory.Container.GetInstance<ApplicationUserManager>());
appBuilder.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = TimeSpan.FromDays(twoWeeks),
SlidingExpiration = true,
CookieName = "decision",
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity =
ProjectObjectFactory.Container.GetInstance<IApplicationUserManager>().OnValidateIdentity()
}
});
ProjectObjectFactory.Container.GetInstance<IApplicationRoleManager>()
.SeedDatabase();
ProjectObjectFactory.Container.GetInstance<IApplicationUserManager>()
.SeedDatabase();
}