@@ -37,6 +37,11 @@ public KeycloakAuthenticationOptions()
37
37
ClaimActions . MapJsonKey ( ClaimTypes . Role , "roles" ) ;
38
38
}
39
39
40
+ /// <summary>
41
+ /// Gets or sets the value for Keycloak client's access type.
42
+ /// </summary>
43
+ public KeycloakAuthenticationAccessType AccessType { get ; set ; }
44
+
40
45
/// <summary>
41
46
/// Gets or sets the base address of the Keycloak server.
42
47
/// </summary>
@@ -51,5 +56,42 @@ public KeycloakAuthenticationOptions()
51
56
/// Gets or sets the Keycloak realm to use for authentication.
52
57
/// </summary>
53
58
public string ? Realm { get ; set ; }
59
+
60
+ /// <inheritdoc />
61
+ public override void Validate ( )
62
+ {
63
+ try
64
+ {
65
+ // HACK
66
+ // We want all of the base validation except for ClientSecret,
67
+ // so rather than re-implement it all, catch the exception thrown
68
+ // for that being null and only throw if we aren't using public access type.
69
+ // This does mean that three checks have to be re-implemented
70
+ // because the won't be validated if the ClientSecret validation fails.
71
+ base . Validate ( ) ;
72
+ }
73
+ catch ( ArgumentException ex ) when ( ex . ParamName == nameof ( ClientSecret ) )
74
+ {
75
+ if ( AccessType != KeycloakAuthenticationAccessType . Public )
76
+ {
77
+ throw ;
78
+ }
79
+ }
80
+
81
+ if ( string . IsNullOrEmpty ( AuthorizationEndpoint ) )
82
+ {
83
+ throw new ArgumentException ( $ "The '{ nameof ( AuthorizationEndpoint ) } ' option must be provided.", nameof ( AuthorizationEndpoint ) ) ;
84
+ }
85
+
86
+ if ( string . IsNullOrEmpty ( TokenEndpoint ) )
87
+ {
88
+ throw new ArgumentException ( $ "The '{ nameof ( TokenEndpoint ) } ' option must be provided.", nameof ( TokenEndpoint ) ) ;
89
+ }
90
+
91
+ if ( ! CallbackPath . HasValue )
92
+ {
93
+ throw new ArgumentException ( $ "The '{ nameof ( CallbackPath ) } ' option must be provided.", nameof ( CallbackPath ) ) ;
94
+ }
95
+ }
54
96
}
55
97
}
0 commit comments