本文整理汇总了C#中Nancy.Authentication.Forms.FormsAuthenticationConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# FormsAuthenticationConfiguration类的具体用法?C# FormsAuthenticationConfiguration怎么用?C# FormsAuthenticationConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FormsAuthenticationConfiguration类属于Nancy.Authentication.Forms命名空间,在下文中一共展示了FormsAuthenticationConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplicationConfiguration
public static void ApplicationConfiguration(TinyIoCContainer container, IPipelines pipelines)
{
var cryptographyConfiguration = new CryptographyConfiguration(
new RijndaelEncryptionProvider(new PassphraseKeyGenerator("SuperSecretPass", new byte[] {1, 2, 3, 4, 5, 6, 7, 8})),
new DefaultHmacProvider(new PassphraseKeyGenerator("UberSuperSecure", new byte[] {1, 2, 3, 4, 5, 6, 7, 8})));
pipelines.AfterRequest.AddItemToEndOfPipeline(x =>
{
x.Response.Headers.Add("Access-Control-Allow-Origin", "*");
x.Response.Headers.Add("Access-Control-Allow-Methods", "POST,GET,PUT,DELETE,OPTIONS");
});
var formsAuthentication = new FormsAuthenticationConfiguration()
{
CryptographyConfiguration = cryptographyConfiguration,
RedirectUrl = "~/weblogin",
UserMapper = container.Resolve<IUserMapper>(),
};
Nancy.Json.JsonSettings.MaxJsonLength = int.MaxValue;
FormsAuthentication.Enable(pipelines, formsAuthentication);
GlobalHost.DependencyResolver = new TinyIoCDependencyResolver(container);
container.Register(typeof (StartableManager), new StartableManager(container));
}
示例2: FixtureSetup
public void FixtureSetup()
{
var formsAuthenticationConfiguration = new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/login",
UserMapper = new FakeUserMapper(new UserService())
};
var configuration = A.Fake<IRazorConfiguration>();
var bootstrapper = new ConfigurableBootstrapper(config =>
{
config.Module<UsersModule>();
config.Module<LoginModule>();
config.ViewEngine(new RazorViewEngine(configuration));
});
var bootstrapper2 = new ConfigurableBootstrapper(config =>
{
config.Module<UsersModule>();
config.Module<LoginModule>();
config.ViewEngine(new RazorViewEngine(configuration));
config.RequestStartup((x, pipelines, z) => FormsAuthentication.Enable(pipelines, formsAuthenticationConfiguration));
});
_notLoggedInBrowser = new Browser(bootstrapper);
_loggedInBrowserResponse = new Browser(bootstrapper2).Post("/login", x =>
{
x.HttpRequest();
x.FormValue("Username", "Chris1");
x.FormValue("Password", "123");
});
}
示例3: Enable
/// <summary>
/// Enables forms authentication for the application
/// </summary>
/// <param name="pipelines">Pipelines to add handlers to (usually "this")</param>
/// <param name="configuration">Forms authentication configuration</param>
public static void Enable(IPipelines pipelines, FormsAuthenticationConfiguration configuration)
{
if (pipelines == null)
{
throw new ArgumentNullException("pipelines");
}
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}
if (!configuration.IsValid)
{
throw new ArgumentException("Configuration is invalid", "configuration");
}
currentConfiguration = configuration;
pipelines.BeforeRequest.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration));
if (!configuration.DisableRedirect)
{
pipelines.AfterRequest.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration));
}
}
示例4: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/login",
UserMapper = container.Resolve<IUserMapper>(),
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
CookieBasedSessions.Enable(pipelines);
pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx =>
{
if (Helper.Settings.Instance.Client.CanConnect)
return null;
else
{
if (String.Compare(ctx.Request.Path, "/notavailable", true) == 0)
{
return null;
}
return new RedirectResponse("/notavailable");
}
});
base.RequestStartup(container, pipelines, context);
}
示例5: RequestStartup
//protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
//{
// // We don't call "base" here to prevent auto-discovery of
// // types/dependencies
//}
//protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
//{
// base.ConfigureRequestContainer(container, context);
// // Here we register our user mapper as a per-request singleton.
// // As this is now per-request we could inject a request scoped
// // database "context" or other request scoped services.
// container.Register<IUserMapper, UserDatabase>();
//}
protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
{
// At request startup we modify the request pipelines to
// include forms authentication - passing in our now request
// scoped user name mapper.
//
// The pipelines passed in here are specific to this request,
// so we can add/remove/update items in them as we please.
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/login",
UserMapper = requestContainer.Resolve<IUserMapper>(),
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
pipelines.AfterRequest.AddItemToEndOfPipeline(x =>
{
if (x.CurrentUser != null)
x.ViewBag.CurrentUserName = x.CurrentUser.UserName;
else
x.ViewBag.CurrentUserName = null;
});
}
示例6: ApplicationStartup
protected override void ApplicationStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
CookieBasedSessions.Enable(pipelines);
Conventions.ViewLocationConventions.Add((viewName, model, context) => string.Concat("views/", viewName));
Conventions.StaticContentsConventions.Add(
StaticContentConventionBuilder.AddDirectory("assets", @"assets")
);
container.Register<IFlexUserStore, FlexMembershipUserStore<User, Role>>();
container.Register(typeof(IDocumentStore), InitDocStore());
container.Register(typeof(IDocumentSession), (c, overloads) =>
c.Resolve<IDocumentStore>().OpenSession());
var cryptographyConfiguration = new CryptographyConfiguration(
new RijndaelEncryptionProvider(new PassphraseKeyGenerator(Configuration.EncryptionKey, new byte[] { 8, 2, 10, 4, 68, 120, 7, 14 })),
new DefaultHmacProvider(new PassphraseKeyGenerator(Configuration.HmacKey, new byte[] { 1, 20, 73, 49, 25, 106, 78, 86 })));
var authenticationConfiguration =
new FormsAuthenticationConfiguration()
{
CryptographyConfiguration = cryptographyConfiguration,
RedirectUrl = "/login",
UserMapper = container.Resolve<IUserMapper>(),
};
FormsAuthentication.Enable(pipelines, authenticationConfiguration);
FlexMembershipProvider.RegisterClient(
new GoogleOpenIdClient(),
"Google", new Dictionary<string, object>());
}
示例7: Enable
/// <summary>
/// Enables forms authentication for a module
/// </summary>
/// <param name="module">Module to add handlers to (usually "this")</param>
/// <param name="configuration">Forms authentication configuration</param>
public static void Enable(INancyModule module, FormsAuthenticationConfiguration configuration)
{
if (module == null)
{
throw new ArgumentNullException("module");
}
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}
configuration.EnsureConfigurationIsValid();
module.RequiresAuthentication();
currentConfiguration = configuration;
module.Before.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration));
if (!configuration.DisableRedirect)
{
module.After.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration));
}
}
示例8: ApplicationStartup
/// <summary>
/// Initialise the bootstrapper - can be used for adding pre/post hooks and
/// any other initialisation tasks that aren't specifically container setup
/// related
/// </summary>
/// <param name="container">Container instance for resolving types if required.</param>
/// <param name="pipelines">The pipelines used in this application.</param>
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
this.SetupDatabaseConnection();
base.ApplicationStartup(container, pipelines);
StaticConfiguration.EnableRequestTracing = true;
pipelines.OnError += (ctx, ex) =>
{
Logger.Trace(ex, "On error message was triggered: {0}", ex.Message);
return null;
};
SetUpTrackingCodes();
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/login",
UserMapper = container.Resolve<IUserMapper>()
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
}
示例9: NancyAuthMiddleware
public NancyAuthMiddleware(Func<IDictionary<string, object>, Task> next,
FormsAuthenticationConfiguration formsAuthenticationConfiguration,
IUserManager userManager)
{
_next = next;
_formsAuthenticationConfiguration = formsAuthenticationConfiguration;
_userManager = userManager;
}
示例10: InitialiseInternal
protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
{
base.InitialiseInternal(container);
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
Passphrase = "SuperSecretPass",
Salt = "AndVinegarCrisps",
HmacPassphrase = "UberSuperSecure",
RedirectUrl = "/authentication/login",
UsernameMapper = container.Resolve<IUsernameMapper>(),
};
FormsAuthentication.Enable(this, formsAuthConfiguration);
BeforeRequest += ctx =>
{
var rootPathProvider =
container.Resolve<IRootPathProvider>();
var staticFileExtensions =
new Dictionary<string, string>
{
{ "jpg", "image/jpg" },
{ "png", "image/png" },
{ "gif", "image/gif" },
{ "css", "text/css" },
{ "js", "text/javascript" }
};
var requestedExtension =
Path.GetExtension(ctx.Request.Uri);
if (!string.IsNullOrEmpty(requestedExtension))
{
var extensionWithoutDot =
requestedExtension.Substring(1);
if (staticFileExtensions.Keys.Any(x => x.Equals(extensionWithoutDot, StringComparison.InvariantCultureIgnoreCase)))
{
var fileName =
Path.GetFileName(ctx.Request.Uri);
if (fileName == null)
{
return null;
}
var filePath =
Path.Combine(rootPathProvider.GetRootPath(), "content", fileName);
return !File.Exists(filePath) ? null : new StaticFileResponse(filePath, staticFileExtensions[extensionWithoutDot]);
}
}
return null;
};
}
示例11: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) {
base.RequestStartup(container, pipelines, context);
var formsAuthConfiguration =
new FormsAuthenticationConfiguration {
RedirectUrl = "~/login",
UserMapper = new UserMapper(),
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
}
示例12: RequestStartup
protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
{
var formsAuthConfiguration = new FormsAuthenticationConfiguration
{
RedirectUrl = "~/",
UserMapper = requestContainer.Resolve<IUserMapper>(),
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
}
示例13: RequestStartup
protected override void RequestStartup(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
var formsAuthConfiguration = new FormsAuthenticationConfiguration()
{
RedirectUrl = "/login", //認証失敗時のリダイレクト先
UserMapper = container.Resolve<IUserMapper>()
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration); //フォーム認証の有効化
}
示例14: FormsAuthenticationRequestStartup
private void FormsAuthenticationRequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
var config = new FormsAuthenticationConfiguration
{
RedirectUrl = "~/login",
UserMapper = container.Resolve<IUserMapper>()
};
FormsAuthentication.Enable(pipelines, config);
}
示例15: RequestStartup
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
var authConfig = new FormsAuthenticationConfiguration()
{
RedirectUrl = "/login",
UserMapper = container.Resolve<IUserMapper>(),
};
FormsAuthentication.Enable(ApplicationPipelines, authConfig);
}