protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, 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 formsAuthConfiguration =
                new FormsAuthenticationConfiguration()
            {
                RedirectUrl = "~/login",
                UserMapper  = container.Resolve <IUserMapper>(),
                CryptographyConfiguration = cryptographyConfiguration
            };

            FormsAuthentication.Enable(pipelines, formsAuthConfiguration);

            OAuth.Enable();

            var configuration =
                new StatelessAuthenticationConfiguration(nancyContext =>
            {
                var apiKey =
                    (string)nancyContext.Request.Query["access_token"].Value;

                return(UserDatabase.GetUserFromToken(apiKey));
            });

            StatelessAuthentication.Enable(pipelines, configuration);

            InMemorySessions.Enable(pipelines);
        }
Beispiel #2
0
 public void SetUp()
 {
     _tokenEndpointService = A.Fake <ITokenEndpointService>();
     _browser = new Browser(with =>
     {
         with.EnableAutoRegistration();
         with.Module <TokenModule>();
         with.Dependency(_tokenEndpointService);
         with.Dependency(new DefaultErrorResponseBuilder());
         with.ApplicationStartup((x, y) => OAuth.Enable());
     });
 }
Beispiel #3
0
 private static Browser GetBrowser()
 {
     return(new Browser(with =>
     {
         with.EnableAutoRegistration();
         with.Module <AuthorizeModule>();
         with.Dependency(new AuthorizationEndpointServiceStub());
         with.Dependency(new DefaultErrorResponseBuilder());
         with.RootPathProvider <TestRootPathProvider>();
         with.ApplicationStartup((x, y) => OAuth.Enable());
         with.RequestStartup((container, pipelines, context) =>
         {
             pipelines.WithSession(new Dictionary <string, object>());
         });
     }));
 }
Beispiel #4
0
 private static Browser GetAuthenticatedBrowser(string username, IDictionary <string, object> session = null)
 {
     return(new Browser(with =>
     {
         with.EnableAutoRegistration();
         with.Module <AuthorizeModule>();
         with.Dependency(new AuthorizationEndpointServiceStub());
         with.Dependency(new DefaultErrorResponseBuilder());
         with.RootPathProvider <TestRootPathProvider>();
         with.ApplicationStartup((x, y) => OAuth.Enable());
         with.RequestStartup((container, pipelines, context) =>
         {
             context.CurrentUser = new TestUserIdentity {
                 UserName = username
             };
             pipelines.WithSession(session ?? new Dictionary <string, object>());
         });
     }));
 }