Пример #1
0
        public void Configure(IAppHost appHost)
        {
            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                new CredentialsAuthProvider(AppSettings),     //Enable UserName/Password Credentials Auth
                new JwtAuthProvider(AppSettings)
                {
                    RequireSecureConnection = false,
                    AuthKey = AesUtils.CreateKey(),     //Transient Auth Key
                },
            }));

            appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();

            appHost.Register <ICacheClient>(new MemoryCacheClient());         //Store User Sessions in Memory

            appHost.Register <IAuthRepository>(new InMemoryAuthRepository()); //Store Authenticated Users in Memory

            CreateUser(appHost, "*****@*****.**", "Admin User", "p@55wOrd", roles: new[] { RoleNames.Admin });
        }
Пример #2
0
        public void Configure(IAppHost appHost)
        {
            var UsernameRegex = new Regex(@"[\.\-\s\w\$\!\@\#\%\^\&\*\(\)]", RegexOptions.Compiled);

            var authKey = EncodeTo64("TimeToseelMyShoes");

            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                new CredentialsAuthProvider(AppSettings)
                {
                    SkipPasswordVerificationForInProcessRequests = true,
                },             /* Sign In with Username / Password credentials */
                new JwtAuthProvider(AppSettings)
                {
                    AuthKeyBase64           = authKey,
                    RequireSecureConnection = false,
                },
            })
            {
                IsValidUsernameFn = (username) => UsernameRegex.IsMatch(username)
            });

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();
        }
        public void Register(IAppHost appHost)
        {
            appHost.RegisterServicesInAssembly(typeof(LayerTokenService).Assembly);

            // if nothing is registered, fallback to the default one.
            if (appHost.TryResolve <ILayerUserValidator>() == null)
            {
                appHost.RegisterAs <ServiceStackSessionUserValidator, ILayerUserValidator>();
            }
        }
Пример #4
0
        public void Configure(IAppHost appHost)
        {
            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                new CredentialsAuthProvider(AppSettings),         /* Sign In with Username / Password credentials */
                new FacebookAuthProvider(AppSettings),            /* Create App https://developers.facebook.com/apps */
                new GoogleAuthProvider(AppSettings),              /* Create App https://console.developers.google.com/apis/credentials */
                new MicrosoftGraphAuthProvider(AppSettings),      /* Create App https://apps.dev.microsoft.com */
            }));

            appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();
        }
Пример #5
0
        public void Configure(IAppHost appHost)
        {
            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                new CredentialsAuthProvider(AppSettings),         /* Sign In with Username / Password credentials */
                new JwtAuthProvider(AppSettings)
                {
                    UseTokenCookie = true
                },
                new AppleAuthProvider(AppSettings)               /* Configure: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple */
                .Use(AppleAuthFeature.FlutterSignInWithApple),
            }));

            appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();
        }
Пример #6
0
        public void Configure(IAppHost appHost)
        {
            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                //new BasicAuthProvider(), //Sign-in with HTTP Basic Auth
                new JwtAuthProvider(AppSettings)
                {
                    AuthKey = AesUtils.CreateKey(),
                    RequireSecureConnection = false,
                },
                new CredentialsAuthProvider(),     //HTML Form post of UserName/Password credentials
                new FacebookAuthProvider(AppSettings),
                new TwitterAuthProvider(AppSettings),
                new GithubAuthProvider(AppSettings),
                new MicrosoftGraphAuthProvider(AppSettings),
            }));

            appHost.Plugins.Add(new RegistrationFeature());

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();

            var userRep = new InMemoryAuthRepository();

            appHost.Register <IAuthRepository>(userRep);

            var authRepo = userRep;

            var newAdmin = new UserAuth {
                Email = "*****@*****.**", DisplayName = "Admin User"
            };
            var user = authRepo.CreateUserAuth(newAdmin, "p@55wOrd");

            authRepo.AssignRoles(user, new List <string> {
                "Admin"
            });
        }
Пример #7
0
        public void Configure(IAppHost appHost)
        {
            // TODO: Replace OAuth App settings in: appsettings.Development.json
            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                new NetCoreIdentityAuthProvider(AppSettings) // Adapter to enable ServiceStack Auth in MVC
                {
                    AdminRoles = { "Manager" },              // Automatically Assign additional roles to Admin Users
                },
                new CredentialsAuthProvider(AppSettings),    /* Sign In with Username / Password credentials */
                new FacebookAuthProvider(AppSettings),       /* Create App https://developers.facebook.com/apps */
                new GoogleAuthProvider(AppSettings),         /* Create App https://console.developers.google.com/apis/credentials */
                new MicrosoftGraphAuthProvider(AppSettings), /* Create App https://apps.dev.microsoft.com */
            }));

            appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();
        }
Пример #8
0
        public void Configure(IAppHost appHost)
        {
            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                new JwtAuthProvider(AppSettings)
                {
                    AuthKeyBase64 = AppSettings.GetString("AuthKeyBase64") ?? "cARl12kvS/Ra4moVBIaVsrWwTpXYuZ0mZf/gNLUhDW5=",
                },
                new CredentialsAuthProvider(AppSettings),         /* Sign In with Username / Password credentials */
                new FacebookAuthProvider(AppSettings),            /* Create App https://developers.facebook.com/apps */
                new GoogleAuthProvider(AppSettings),              /* Create App https://console.developers.google.com/apis/credentials */
                new MicrosoftGraphAuthProvider(AppSettings),      /* Create App https://apps.dev.microsoft.com */
            })
            {
                IncludeDefaultLogin = false
            });

            appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();
        }
 public void Register(IAppHost appHost)
 {
     appHost.RegisterService<RegistrationService>(AtRestPath);
     appHost.RegisterAs<RegistrationValidator, IValidator<Registration>>();
 }
Пример #10
0
 public void Register(IAppHost appHost)
 {
     appHost.RegisterService <RegistrationService>(AtRestPath);
     appHost.RegisterAs <RegistrationValidator, IValidator <Registration> >();
 }
Пример #11
0
 public void Register(IAppHost appHost)
 {
     appHost.LoadPlugin(new ValidationFeature());
     appHost.GetContainer().RegisterValidators(typeof(TTFPlugin).Assembly);
     appHost.RegisterAs <MappingAlgorithmFactory, IMappingAlgorithmFactory>();
 }
Пример #12
0
 public void Register(IAppHost appHost)
 {
     appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();
 }
Пример #13
0
 public static void Init(IAppHost appHost)
 {
     appHost.RegisterService <RegistrationService>();
     appHost.RegisterAs <RegistrationValidator, IValidator <Registration> >();
 }
Пример #14
0
        public void Configure(IAppHost appHost)
        {
            var AppSettings = appHost.AppSettings;

            appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                                new IAuthProvider[] {
                new ApiKeyAuthProvider(AppSettings)
                {
                    KeyTypes = new[] { "secret", "publishable" },
                },
                new NetCoreIdentityAuthProvider(AppSettings) // Adapter to enable ServiceStack Auth in MVC
                {
                    AdminRoles            = { "Manager" },   // Automatically Assign additional roles to Admin Users
                    CreateClaimsPrincipal = (claims, session, req) =>
                    {
                        var apiRepo = (IManageApiKeys)HostContext.TryResolve <IAuthRepository>();
                        var apiKeys = apiRepo.GetUserApiKeys(session.UserAuthId);
                        var apiKey  = apiKeys.First(k => k.KeyType == "publishable" && k.Environment == "live");
                        claims.Add(new Claim("ApiKey", apiKey.Id));
                        var identity = new ClaimsIdentity(claims, "Identity.Application");
                        return(new ClaimsPrincipal(identity));
                    }
                },
                new CredentialsAuthProvider(AppSettings),     // Sign In with Username / Password credentials
                new FacebookAuthProvider(AppSettings),        // Create App at: https://developers.facebook.com/apps
                new TwitterAuthProvider(AppSettings),         // Create App at: https://dev.twitter.com/apps
                new GoogleAuthProvider(AppSettings),          // https://console.developers.google.com/apis/credentials
                new MicrosoftGraphAuthProvider(AppSettings),  // Create App https://apps.dev.microsoft.com
            }));

            appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

            //override the default registration validation with your own custom implementation
            appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();


            appHost.AfterInitCallbacks.Add(host =>
            {
                try
                {
                    var authProvider = (ApiKeyAuthProvider)AuthenticateService.GetAuthProviders()
                                       .First(x => x is ApiKeyAuthProvider);
                    using (var db = host.TryResolve <IDbConnectionFactory>().Open())
                    {
                        var userWithKeysIds = db.Column <string>(db.From <ApiKey>()
                                                                 .SelectDistinct(x => x.UserAuthId)).Map(int.Parse);

                        var userIdsMissingKeys = db.Column <string>(db.From <AppUser>()
                                                                    .Where(x => userWithKeysIds.Count == 0 || !userWithKeysIds.Contains(x.Id))
                                                                    .Select(x => x.Id));

                        var authRepo = (IManageApiKeys)host.TryResolve <IAuthRepository>();
                        foreach (var userId in userIdsMissingKeys)
                        {
                            var apiKeys = authProvider.GenerateNewApiKeys(userId.ToString());
                            authRepo.StoreAll(apiKeys);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            });
        }