Esempio n. 1
0
            public override void Configure(Funq.Container container)
            {
                Routes
                    .Add<Hello>("/hello")
                    .Add<Hello>("/hello/{Name}");
                helloService = container.Resolve<HelloService>();

                AuthFeature authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {new BasicAuthProvider(), new TwitterAuthProvider(new AppSettings()),});
                //authFeature.HtmlRedirect
                Plugins.Add(authFeature);
                MemoryCacheClient memoryCacheClient = new MemoryCacheClient();
                container.Register<ICacheClient>(memoryCacheClient);

                var userRepository = new InMemoryAuthRepository();
                container.Register<IUserAuthRepository>(userRepository);

                string hash;
                string salt;
                string password = "******";
                new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
                userRepository.CreateUserAuth(
                    new UserAuth {
                        Id = 1,
                        DisplayName = "JoeUser",
                        Email = "*****@*****.**",
                        UserName = "******",
                        FirstName = "Joe",
                        LastName = "User",
                        PasswordHash = hash,
                        Salt = salt,
                    }, password);
                //IHttpResult authenticationRequired = helloService.AuthenticationRequired(); // ????
            }
Esempio n. 2
0
 private void ConfigureAuthentication()
 {
     var authProviders = new IAuthProvider[]
         {
             new ServiceStackCredentialsAuthAdapter(this.unityContainer)
         };
     var authFeature = new AuthFeature(() => new AuthUserSession(), authProviders)
         {
            IncludeAssignRoleServices = false
         };
     this.Plugins.Add(authFeature);
 }
        public static void SaveSession(this IHttpRequest httpReq, IAuthSession session, TimeSpan? expiresIn = null)
        {
            if (httpReq == null) return;

            using (var cache = httpReq.GetCacheClient())
            {
                var sessionKey = SessionFeature.GetSessionKey(httpReq.GetSessionId());
                cache.CacheSet(sessionKey, session, expiresIn ?? AuthFeature.GetDefaultSessionExpiry());
            }

            httpReq.Items[RequestItemsSessionKey] = session;
        }
Esempio n. 4
0
        public override void Configure(Container container)
        {
            var factory = new SqLiteConnectionFactory()
            {
                ConnectionString = SqliteFile
            };

            if (enableBackups)
            {
                backupDaemon = new BackupDaemon(factory, TimeSpan.FromMinutes(BackupPeriodMinutes));
            }

            container.Register<IThingsRepository>(new ThingsRepository(factory));
            container.Register<IOpinionsRepository>(new OpinionsRepository(factory));
            container.Register<IUsersRepository>(new UsersRepository(factory));

            container.Register<ICacheClient>(new MemoryCacheClient() { FlushOnDispose = false });

            var authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {
                new SiouxAuthProvider()
            })
            {
                ServiceRoutes = new Dictionary<Type, string[]>
                {
                    { typeof(AuthService), new[]{"/api/auth", "/api/auth/{provider}"} },
                    { typeof(AssignRolesService), new[]{"/assignroles"} },
                    { typeof(UnAssignRolesService), new[]{"/unassignroles"} },
                },
                HtmlRedirect = null, // don't redirect to some login page on unauthorized access.
            };
            Plugins.Add(authFeature);

            SetConfig(new EndpointHostConfig
            {
                ServiceStackHandlerFactoryPath = "api",
                MetadataRedirectPath = "api/metadata",
                DebugMode = true, //Show StackTraces in service responses during development
            });
        }