3
3
using ServiceStack . Auth ;
4
4
using ServiceStack . FluentValidation ;
5
5
6
+ [ assembly: HostingStartup ( typeof ( MyApp . ConfigureAuth ) ) ]
7
+
6
8
namespace MyApp
7
9
{
8
10
// Add any additional metadata properties you want to store in the Users Typed Session
9
11
public class CustomUserSession : AuthUserSession
10
12
{
11
13
}
12
14
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
14
16
public class CustomRegistrationValidator : RegistrationValidator
15
17
{
16
18
public CustomRegistrationValidator ( )
@@ -23,29 +25,27 @@ public CustomRegistrationValidator()
23
25
}
24
26
}
25
27
26
- public class ConfigureAuth : IConfigureAppHost , IConfigureServices
28
+ public class ConfigureAuth : IHostingStartup
27
29
{
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
+ } ) ) ;
32
44
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
44
46
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
+ } ) ;
50
50
}
51
- }
51
+ }
0 commit comments