33using ServiceStack . Auth ;
44using ServiceStack . FluentValidation ;
55
6+ [ assembly: HostingStartup ( typeof ( MyApp . ConfigureAuth ) ) ]
7+
68namespace MyApp
79{
810 // Add any additional metadata properties you want to store in the Users Typed Session
911 public class CustomUserSession : AuthUserSession
1012 {
1113 }
1214
13- // Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
15+ // Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
1416 public class CustomRegistrationValidator : RegistrationValidator
1517 {
1618 public CustomRegistrationValidator ( )
@@ -23,29 +25,27 @@ public CustomRegistrationValidator()
2325 }
2426 }
2527
26- public class ConfigureAuth : IConfigureAppHost , IConfigureServices
28+ public class ConfigureAuth : IHostingStartup
2729 {
28- public void Configure ( IServiceCollection services )
29- {
30- //services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
31- }
30+ public void Configure ( IWebHostBuilder builder ) => builder
31+ . ConfigureServices ( services => {
32+ //services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
33+ } )
34+ . ConfigureAppHost ( appHost => {
35+ var appSettings = appHost . AppSettings ;
36+ appHost . Plugins . Add ( new AuthFeature ( ( ) => new CustomUserSession ( ) ,
37+ new IAuthProvider [ ] {
38+ new CredentialsAuthProvider ( appSettings ) , /* Sign In with Username / Password credentials */
39+ new AppleAuthProvider ( appSettings ) , /* Configure: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple */
40+ new FacebookAuthProvider ( appSettings ) , /* Create App https://developers.facebook.com/apps */
41+ new GoogleAuthProvider ( appSettings ) , /* Create App https://console.developers.google.com/apis/credentials */
42+ new MicrosoftGraphAuthProvider ( appSettings ) , /* Create App https://apps.dev.microsoft.com */
43+ } ) ) ;
3244
33- public void Configure ( IAppHost appHost )
34- {
35- var AppSettings = appHost . AppSettings ;
36- appHost . Plugins . Add ( new AuthFeature ( ( ) => new CustomUserSession ( ) ,
37- new IAuthProvider [ ] {
38- new CredentialsAuthProvider ( AppSettings ) , /* Sign In with Username / Password credentials */
39- new AppleAuthProvider ( AppSettings ) , /* Configure: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple */
40- new FacebookAuthProvider ( AppSettings ) , /* Create App https://developers.facebook.com/apps */
41- new GoogleAuthProvider ( AppSettings ) , /* Create App https://console.developers.google.com/apis/credentials */
42- new MicrosoftGraphAuthProvider ( AppSettings ) , /* Create App https://apps.dev.microsoft.com */
43- } ) ) ;
45+ appHost . Plugins . Add ( new RegistrationFeature ( ) ) ; //Enable /register Service
4446
45- appHost . Plugins . Add ( new RegistrationFeature ( ) ) ; //Enable /register Service
46-
47- //override the default registration validation with your own custom implementation
48- appHost . RegisterAs < CustomRegistrationValidator , IValidator < Register > > ( ) ;
49- }
47+ //override the default registration validation with your own custom implementation
48+ appHost . RegisterAs < CustomRegistrationValidator , IValidator < Register > > ( ) ;
49+ } ) ;
5050 }
51- }
51+ }
0 commit comments