Example #1
0
        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));
        }
Example #2
0
        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>());
        }
        protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines)
        {
            // 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.

            CryptographyConfiguration cryptoConfig = new CryptographyConfiguration(
                    new RijndaelEncryptionProvider(new DokukuKeyGenerator()),
                    new DefaultHmacProvider(new DokukuKeyGenerator()));

            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration(cryptoConfig)
                {
                    RedirectUrl = System.Configuration.ConfigurationManager.AppSettings["LoginUrl"],
                    UserMapper = requestContainer.Resolve<IUserMapper>(),
                };

            FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
            Jsonp.Enable(pipelines);
            pipelines.AfterRequest.AddItemToEndOfPipeline(SetCookieDomain);
            requestContainer.Register<RazorViewEngine>();
        }
 protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
 {
     // create the cryptography config
     StaticConfiguration.DisableErrorTraces = false;
     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 })));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DiagnosticsConfiguration"/> class
 /// </summary>
 /// <param name="password">Password used to secure the dashboard.</param>
 /// <param name="path">Relative path of the dashboard.</param>
 /// <param name="cookieName">Name of the cookie to store diagnostics information.</param>
 /// <param name="slidingTimeout">Number of minutes that expiry of the diagnostics dashboard.</param>
 /// <param name="cryptographyConfiguration">Cryptography config to use for securing the dashboard.</param>
 public DiagnosticsConfiguration(string password, string path, string cookieName, int slidingTimeout, CryptographyConfiguration cryptographyConfiguration)
 {
     this.Password = password ?? Default.Password;
     this.Path = GetNormalizedPath(path ?? Default.Path);
     this.CookieName = cookieName ?? Default.CookieName;
     this.SlidingTimeout = slidingTimeout;
     this.CryptographyConfiguration = cryptographyConfiguration ?? Default.CryptographyConfiguration;
 }
 /// <summary>
 /// Configures diagnostics.
 /// </summary>
 /// <param name="environment"><see cref="INancyEnvironment"/> that should be configured.</param>
 /// <param name="password">Password used to secure the dashboard.</param>
 /// <param name="path">Relative path of the dashboard.</param>
 /// <param name="cookieName">Name of the cookie to store diagnostics information.</param>
 /// <param name="slidingTimeout">Number of minutes that expiry of the diagnostics dashboard.</param>
 /// <param name="cryptographyConfiguration">Cryptography config to use for securing the dashboard.</param>
 public static void Diagnostics(this INancyEnvironment environment, string password, string path = null, string cookieName = null, int slidingTimeout = 15, CryptographyConfiguration cryptographyConfiguration = null)
 {
     environment.AddValue(new DiagnosticsConfiguration(
         password,
         path,
         cookieName,
         slidingTimeout,
         cryptographyConfiguration));
 }
Example #7
0
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);
            //need to replace default CryptographyConfiguration for the form authentication
            //because defaut KeyGenerator generate on each app startup new keys and cookies invalidate after that
            this._cryptographyConfiguration = new CryptographyConfiguration(
                new RijndaelEncryptionProvider(new PassphraseKeyGenerator("SuperSecretPass", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })),
                new DefaultHmacProvider(new PassphraseKeyGenerator("UberSuperSecure1", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })));

            CookieBasedSessions.Enable(pipelines);
        }
 /// <summary>
 /// Configures diagnostics.
 /// </summary>
 /// <param name="environment"><see cref="INancyEnvironment"/> that should be configured.</param>
 /// <param name="password">Password used to secure the dashboard.</param>
 /// <param name="path">Relative path of the dashboard.</param>
 /// <param name="cookieName">Name of the cookie to store diagnostics information.</param>
 /// <param name="slidingTimeout">Number of minutes that expiry of the diagnostics dashboard.</param>
 /// <param name="cryptographyConfiguration">Cryptography config to use for securing the dashboard.</param>
 /// <remarks>This will implicitly enable diagnostics. If you need control, please explicitly set enabled to either <see langword="true"/> or <see langword="false"/>.</remarks>
 public static void Diagnostics(this INancyEnvironment environment, string password, string path = null, string cookieName = null, int slidingTimeout = 15, CryptographyConfiguration cryptographyConfiguration = null)
 {
     Diagnostics(
         environment,
         enabled: true,
         password: password,
         path: path,
         cookieName: cookieName,
         slidingTimeout: slidingTimeout,
         cryptographyConfiguration: cryptographyConfiguration);
 }
        public CookieBasesSessionsConfigurationFixture()
        {
            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 })));

            this.config = new CookieBasedSessionsConfiguration()
            {
                CryptographyConfiguration = cryptographyConfiguration,
                Serializer = A.Fake<IObjectSerializer>()
            };
        }
        public FormsAuthenticationConfigurationFixture()
        {
            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 })));

            this.config = new FormsAuthenticationConfiguration()
                              {
                                  CryptographyConfiguration = cryptographyConfiguration,
                                  RedirectUrl = "/login",
                                  UserMapper = A.Fake<IUserMapper>(),
                              };
        }
        private void RegisterFormsAuth(IPipelines pipelines)
        {
            var cryptographyConfiguration = new CryptographyConfiguration(
                    new RijndaelEncryptionProvider(new PassphraseKeyGenerator(_configService.RijndaelPassphrase, Encoding.ASCII.GetBytes(_configService.RijndaelSalt))),
                    new DefaultHmacProvider(new PassphraseKeyGenerator(_configService.HmacPassphrase, Encoding.ASCII.GetBytes(_configService.HmacSalt)))
                );

            FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration
            {
                RedirectUrl = _configFileProvider.UrlBase + "/login",
                UserMapper = _authenticationService,
                CryptographyConfiguration = cryptographyConfiguration
            });
        }
Example #12
0
        /// <summary>
        /// Creates a new csrf token for this response with an optional salt.
        /// Only necessary if a particular route requires a new token for each request.
        /// </summary>
        /// <param name="module">Nancy module</param>
        /// <returns></returns>
        public static void CreateNewCsrfToken(this INancyModule module, CryptographyConfiguration cryptographyConfiguration = null)
        {
            cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration;

            var token = new CsrfToken
            {
                CreatedDate = DateTime.Now,
            };
            token.CreateRandomBytes();
            token.CreateHmac(cryptographyConfiguration.HmacProvider);

            var tokenString = CsrfApplicationStartup.ObjectSerializer.Serialize(token);

            module.Context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString;
        }
Example #13
0
        /// <summary>
        /// Enables Csrf token generation.
        /// This is disabled by default.
        /// </summary>
        /// <param name="pipelines">Application pipelines</param>
        public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null)
        {
            cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration;

            var postHook = new PipelineItem<Action<NancyContext>>(
                CsrfHookName,
                context =>
                {
                    if (context.Response == null || context.Response.Cookies == null || context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY))
                    {
                        context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY,
                                                                     (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY],
                                                                     true));
                        return;
                    }

                    if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY))
                    {
                        var decodedValue = HttpUtility.UrlDecode(context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY]);
                        var cookieToken = CsrfApplicationStartup.ObjectSerializer.Deserialize(decodedValue) as CsrfToken;

                        if (CsrfApplicationStartup.TokenValidator.CookieTokenStillValid(cookieToken))
                        {
                            context.Items[CsrfToken.DEFAULT_CSRF_KEY] = decodedValue;
                            return;
                        }
                    }

                    var token = new CsrfToken
                    {
                        CreatedDate = DateTime.Now,
                    };
                    token.CreateRandomBytes();
                    token.CreateHmac(cryptographyConfiguration.HmacProvider);
                    var tokenString = CsrfApplicationStartup.ObjectSerializer.Serialize(token);

                    context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString;
                    context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true));
                });

            pipelines.AfterRequest.AddItemToEndOfPipeline(postHook);
        }
        protected override void ApplicationStartup(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 })));

            var config =
                new FormsAuthenticationConfiguration()
                {
                        
                    CryptographyConfiguration = cryptographyConfiguration,
                    RedirectUrl = "/login",
                    UserMapper = container.Resolve<IUserDatabase>() as IUserMapper,
                };

            FormsAuthentication.Enable(pipelines, config);
        }
 public void Configuration(IAppBuilder builder)
 {
     var userManager = new UserManager();
     var cryptographyConfiguration = new CryptographyConfiguration(
         new RijndaelEncryptionProvider(new PassphraseKeyGenerator("SuperSecretPass", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 1000)),
         new DefaultHmacProvider(new PassphraseKeyGenerator("UberSuperSecure", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 1000)));
     var formsAuthenticationConfiguration = new FormsAuthenticationConfiguration
                                            {
                                                RedirectUrl = "~/login",
                                                DisableRedirect = true,
                                                UserMapper = userManager,
                                                CryptographyConfiguration = cryptographyConfiguration
                                            };
     builder
         .UseNancyAuth(formsAuthenticationConfiguration, userManager)
         .UseNancy(new AppBootstrapper(formsAuthenticationConfiguration, userManager));
 }
Example #16
0
        public CsrfStartupFixture()
        {
            this.pipelines = new MockPipelines();

            this.cryptographyConfiguration = CryptographyConfiguration.Default;

            this.objectSerializer = new DefaultObjectSerializer();
            var csrfStartup = new CsrfStartup(
                this.cryptographyConfiguration,
                this.objectSerializer,
                new DefaultCsrfTokenValidator(this.cryptographyConfiguration));

            csrfStartup.Initialize(this.pipelines);

            this.request = new FakeRequest("GET", "/");
            this.response = new Response();
        }
        /// <summary>
        /// Configures authentication for the specified <paramref name="pipelines"/>
        /// using the specified <paramref name="userMapper"/>.
        /// </summary>
        /// <param name="pipelines"></param>
        /// <param name="userMapper"></param>
        public static void RegisterAuthentication(IPipelines pipelines, IUserMapper userMapper)
        {
            Verify.NotNull(userMapper, nameof(userMapper));

            var keyGenerator = new PassphraseKeyGenerator(KEY, Salt);

            var encryptionProvider = new RijndaelEncryptionProvider(keyGenerator);
            var hmacProvider = new DefaultHmacProvider(keyGenerator);
            var cryptographyConfiguration = new CryptographyConfiguration(encryptionProvider, hmacProvider);

            var formsConfiguration = new FormsAuthenticationConfiguration(cryptographyConfiguration)
            {
                RedirectUrl = "~/sign-in",
                UserMapper = userMapper
            };

            FormsAuthentication.Enable(pipelines, formsConfiguration);
        }
        public FormsAuthenticationFixture()
        {
            this.cryptographyConfiguration = new CryptographyConfiguration(
                new RijndaelEncryptionProvider(new PassphraseKeyGenerator("SuperSecretPass", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 1000)),
                new DefaultHmacProvider(new PassphraseKeyGenerator("UberSuperSecure", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 1000)));

            this.config = new FormsAuthenticationConfiguration()
            {
                CryptographyConfiguration = this.cryptographyConfiguration,
                RedirectUrl = "/login",
                UserMapper = A.Fake<IUserMapper>(),
                RequiresSSL = false
            };

            this.secureConfig = new FormsAuthenticationConfiguration()
            {
                CryptographyConfiguration = this.cryptographyConfiguration,
                RedirectUrl = "/login",
                UserMapper = A.Fake<IUserMapper>(),
                RequiresSSL = true
            };

            this.domainPathConfig = new FormsAuthenticationConfiguration()
            {
                CryptographyConfiguration = this.cryptographyConfiguration,
                RedirectUrl = "/login",
                UserMapper = A.Fake<IUserMapper>(),
                RequiresSSL = false,
                Domain = domain,
                Path = path
            };

            this.context = new NancyContext
                               {
                                    Request = new Request(
                                                    "GET",
                                                    new Url { Scheme = "http", BasePath = "/testing", HostName = "test.com", Path = "test" })
                               };

            this.userGuid = new Guid("3D97EB33-824A-4173-A2C1-633AC16C1010");
        }
Example #19
0
        /// <summary>
        /// Enables Csrf token generation.
        /// This is disabled by default.
        /// </summary>
        /// <param name="pipelines">Application pipelines</param>
        public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null)
        {
            cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration;

            var postHook = new PipelineItem<Action<NancyContext>>(
                CsrfHookName,
                context =>
                {
                    if (context.Response == null || context.Response.Cookies == null || context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY))
                    {
                        context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY,
                                                                     (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY],
                                                                     true));
                        return;
                    }

                    if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY))
                    {
                        var cookieValue = context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY];
                        var cookieToken = CsrfApplicationStartup.ObjectSerializer.Deserialize(cookieValue) as CsrfToken;

                        if (CsrfApplicationStartup.TokenValidator.CookieTokenStillValid(cookieToken))
                        {
                            context.Items[CsrfToken.DEFAULT_CSRF_KEY] = cookieValue;
                            return;
                        }
                    }

                    var tokenString = GenerateTokenString(cryptographyConfiguration);

                    context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString;
                    context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true));
                });

            pipelines.AfterRequest.AddItemToEndOfPipeline(postHook);
        }
        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.

            // create a custom cryptography config
            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 })));

            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration
                {
                    RedirectUrl = "~/login",
                    UserMapper = requestContainer.Resolve<IUserMapper>(),
                    CryptographyConfiguration = cryptographyConfiguration
                };

            FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
        }
        protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
        {
            base.RequestStartup(container, pipelines, context);

            var aesPassphrase = context.Environment["GTDPad.AESPassphrase"].ToString();
            var hmacPassphrase = context.Environment["GTDPad.HMACPassphrase"].ToString();

            var cryptographyConfiguration = new CryptographyConfiguration(
                new AesEncryptionProvider(new PassphraseKeyGenerator(aesPassphrase, new byte[] { 94, 132, 251, 176, 174, 17, 247, 23 })),
                new DefaultHmacProvider(new PassphraseKeyGenerator(hmacPassphrase, new byte[] { 220, 141, 215, 209, 243, 217, 174, 245 }))
            );

            var formsAuthConfiguration = new FormsAuthenticationConfiguration {
                CryptographyConfiguration = cryptographyConfiguration,
                RedirectUrl = context.Environment["GTDPad.LoginRedirect"].ToString(),
                UserMapper = container.Resolve<IUserMapper>(),
                RequiresSSL = !Convert.ToBoolean(context.Environment["GTDPad.DevMode"])
            };

            FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FormsAuthenticationConfiguration"/> class.
 /// </summary>
 /// <param name="cryptographyConfiguration">Cryptography configuration</param>
 public FormsAuthenticationConfiguration(CryptographyConfiguration cryptographyConfiguration)
 {
     CryptographyConfiguration = cryptographyConfiguration;
 }
        public void Should_set_Path_when_config_provides_path_value()
        {
            //Given
            var cryptoConfig = new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider);
            var storeConfig = new CookieBasedSessionsConfiguration(cryptoConfig)
            {
                Path = "/",
                Serializer = this.fakeObjectSerializer
            };
            var store = new CookieBasedSessions(storeConfig);

            //When
            var response = new Response();
            var session = new Session(new Dictionary<string, object>
                                          {
                                              {"key1", "val1"},
                                          });
            session["key2"] = "val2";
            store.Save(session, response);

            //Then
            var cookie = response.Cookies.First(c => c.Name == storeConfig.CookieName);
            cookie.Path.ShouldEqual(storeConfig.Path);
        }
        public void Should_use_CookieName_when_config_provides_cookiename_value()
        {
            //Given
            var cryptoConfig = new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider);
            var storeConfig = new CookieBasedSessionsConfiguration(cryptoConfig)
            {
                CookieName = "NamedCookie",
                Serializer = this.fakeObjectSerializer
            };
            var store = new CookieBasedSessions(storeConfig);

            //When
            var response = new Response();
            var session = new Session(new Dictionary<string, object>
                                        {
                                            {"key1", "val1"},
                                        });
            session["key2"] = "val2";
            store.Save(session, response);

            //Then
            response.Cookies.ShouldHave(c => c.Name == storeConfig.CookieName);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FormsAuthenticationConfiguration"/> class.
 /// </summary>
 /// <param name="cryptographyConfiguration">Cryptography configuration</param>
 public FormsAuthenticationConfiguration(CryptographyConfiguration cryptographyConfiguration)
 {
     CryptographyConfiguration = cryptographyConfiguration;
     RedirectQuerystringKey = DefaultRedirectQuerystringKey;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultCsrfTokenValidator"/> class,
 /// using the provided <paramref name="cryptoConfig"/>.
 /// </summary>
 /// <param name="cryptoConfig">The <see cref="CryptographyConfiguration"/> that should be used.</param>
 public DefaultCsrfTokenValidator(CryptographyConfiguration cryptoConfig)
 {
     this.hmacProvider = cryptoConfig.HmacProvider;
 }
 public CustomInteractiveDiagnosticsHookFixture()
 {
     this.cryptoConfig = CryptographyConfiguration.Default;
     this.objectSerializer = new DefaultObjectSerializer();
 }
Example #28
0
 /// <summary>
 /// Creates a new csrf token for this response with an optional salt.
 /// Only necessary if a particular route requires a new token for each request.
 /// </summary>
 /// <param name="module">Nancy module</param>
 /// <returns></returns>
 public static void CreateNewCsrfToken(this INancyModule module, CryptographyConfiguration cryptographyConfiguration = null)
 {
     var tokenString = GenerateTokenString(cryptographyConfiguration);
     module.Context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString;
 }
Example #29
0
 /// <summary>
 /// Creates a new csrf token with an optional salt.
 /// Does not store the token in context.
 /// </summary>
 /// <returns>The generated token</returns>
 internal static string GenerateTokenString(CryptographyConfiguration cryptographyConfiguration = null)
 {
     cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration;
     var token = new CsrfToken
     {
         CreatedDate = DateTime.Now,
     };
     token.CreateRandomBytes();
     token.CreateHmac(cryptographyConfiguration.HmacProvider);
     var tokenString = CsrfApplicationStartup.ObjectSerializer.Serialize(token);
     return tokenString;
 }
Example #30
0
 /// <summary>
 /// Initialise and add cookie based session hooks to the application pipeline
 /// </summary>
 /// <param name="pipelines">Application pipelines</param>
 /// <param name="cryptographyConfiguration">Cryptography configuration</param>
 /// <returns>Formatter selector for choosing a non-default serializer</returns>
 public static IObjectSerializerSelector Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration)
 {
     var cookieBasedSessionsConfiguration = new CookieBasedSessionsConfiguration(cryptographyConfiguration)
     {
         Serializer = new DefaultObjectSerializer()
     };
     return Enable(pipelines, cookieBasedSessionsConfiguration);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthenticatorConfiguration"/> class.
 /// </summary>
 /// <param name="cryptographyConfiguration">Cryptography configuration</param>
 public AuthenticatorConfiguration(CryptographyConfiguration cryptographyConfiguration)
 {
     _cryptographyConfiguration = cryptographyConfiguration;
 }