@@ -8,27 +8,51 @@ namespace Aspire.Hosting.Keycloak;
8
8
/// <summary>
9
9
/// Represents a Keycloak Realm resource.
10
10
/// </summary>
11
- /// <param name="name">The name of the realm resource.</param>
12
- /// <param name="realmName">The name of the realm.</param>
13
- /// <param name="parent">The Keycloak server resource associated with this database.</param>
14
- public sealed class KeycloakRealmResource ( string name , string realmName , KeycloakResource parent ) : Resource ( name ) , IResourceWithParent < KeycloakResource > , IResourceWithConnectionString
11
+ public sealed class KeycloakRealmResource : Resource , IResourceWithParent < KeycloakResource > , IResourceWithConnectionString
15
12
{
16
13
private EndpointReference ? _parentEndpoint ;
17
- private EndpointReference ParentEndpoint => _parentEndpoint ??= new ( Parent , "http" ) ;
14
+ private EndpointReferenceExpression ? _parentUrl ;
15
+
16
+ /// <summary>
17
+ /// Initializes a new instance of the <see cref="KeycloakRealmResource"/> class.
18
+ /// </summary>
19
+ /// <param name="name">The name of the realm resource.</param>
20
+ /// <param name="realmName">The name of the realm.</param>
21
+ /// <param name="parent">The Keycloak server resource associated with this database.</param>
22
+ public KeycloakRealmResource ( string name , string realmName , KeycloakResource parent ) : base ( name )
23
+ {
24
+ ArgumentException . ThrowIfNullOrWhiteSpace ( realmName ) ;
25
+ ArgumentNullException . ThrowIfNull ( parent ) ;
26
+
27
+ RealmName = realmName ;
28
+ RealmPath = $ "realms/{ realmName } ";
29
+ Parent = parent ;
30
+ }
31
+
32
+ private EndpointReferenceExpression ParentUrl => _parentUrl ??= ParentEndpoint . Property ( EndpointProperty . Url ) ;
33
+
34
+ /// <summary>
35
+ /// Gets the parent endpoint reference.
36
+ /// </summary>
37
+ public EndpointReference ParentEndpoint => _parentEndpoint ??= new ( Parent , "http" ) ;
18
38
19
39
/// <inheritdoc/>
20
- public ReferenceExpression ConnectionStringExpression => ReferenceExpression . Create ( $ "{ ParentEndpoint . Property ( EndpointProperty . Url ) } /realms/{ RealmName } /") ;
40
+ public ReferenceExpression ConnectionStringExpression => ReferenceExpression . Create ( $ "{ ParentUrl } /{ RealmPath } /") ;
41
+
42
+ /// <summary>
43
+ /// Gets the base address of the realm.
44
+ /// </summary>
45
+ public string RealmPath { get ; }
21
46
22
47
/// <summary>
23
48
/// Gets the issuer expression for the Keycloak realm.
24
49
/// </summary>
25
- public ReferenceExpression IssuerExpression => ReferenceExpression . Create (
26
- $ "{ ParentEndpoint . Property ( EndpointProperty . Url ) } /realms/{ RealmName } ") ;
50
+ public ReferenceExpression IssuerUrlExpression => ReferenceExpression . Create ( $ "{ ParentUrl } /{ RealmPath } ") ;
27
51
28
52
/// <summary>
29
53
/// Gets or sets the metadata address for the Keycloak realm.
30
54
/// </summary>
31
- public string MetadataAddress { get ; set ; } = ".well-known/openid-configuration" ;
55
+ public string MetadataAddress => ".well-known/openid-configuration" ;
32
56
33
57
/// <summary>
34
58
/// Gets the metadata address expression for the Keycloak realm.
@@ -38,7 +62,7 @@ public sealed class KeycloakRealmResource(string name, string realmName, Keycloa
38
62
/// <summary>
39
63
/// Gets or sets the 'authorization_endpoint' for the Keycloak realm.
40
64
/// </summary>
41
- public string AuthorizationEndpoint { get ; set ; } = "protocol/openid-connect/auth" ;
65
+ public string AuthorizationEndpoint => "protocol/openid-connect/auth" ;
42
66
43
67
/// <summary>
44
68
/// Gets the 'authorization_endpoint' expression for the Keycloak realm.
@@ -48,7 +72,7 @@ public sealed class KeycloakRealmResource(string name, string realmName, Keycloa
48
72
/// <summary>
49
73
/// Gets or sets the 'token_endpoint' for the Keycloak realm.
50
74
/// </summary>
51
- public string TokenEndpoint { get ; set ; } = "protocol/openid-connect/token" ;
75
+ public string TokenEndpoint => "protocol/openid-connect/token" ;
52
76
53
77
/// <summary>
54
78
/// Gets the 'token_endpoint' expression for the Keycloak realm.
@@ -58,7 +82,7 @@ public sealed class KeycloakRealmResource(string name, string realmName, Keycloa
58
82
/// <summary>
59
83
/// Gets or sets the 'introspection_endpoint' for the Keycloak realm.
60
84
/// </summary>
61
- public string IntrospectionEndpoint { get ; set ; } = "protocol/openid-connect/token/introspect" ;
85
+ public string IntrospectionEndpoint => "protocol/openid-connect/token/introspect" ;
62
86
63
87
/// <summary>
64
88
/// Gets the 'introspection_endpoint' expression for the Keycloak realm.
@@ -68,7 +92,7 @@ public sealed class KeycloakRealmResource(string name, string realmName, Keycloa
68
92
/// <summary>
69
93
/// Gets or sets 'user_info_endpoint' for the Keycloak realm.
70
94
/// </summary>
71
- public string UserInfoEndpoint { get ; set ; } = "protocol/openid-connect/userinfo" ;
95
+ public string UserInfoEndpoint => "protocol/openid-connect/userinfo" ;
72
96
73
97
/// <summary>
74
98
/// Gets 'user_info_endpoint' expression for the Keycloak realm.
@@ -78,7 +102,7 @@ public sealed class KeycloakRealmResource(string name, string realmName, Keycloa
78
102
/// <summary>
79
103
/// Gets or sets the 'end_session_endpoint' for the Keycloak realm.
80
104
/// </summary>
81
- public string EndSessionEndpoint { get ; set ; } = "protocol/openid-connect/logout" ;
105
+ public string EndSessionEndpoint => "protocol/openid-connect/logout" ;
82
106
83
107
/// <summary>
84
108
/// Gets the 'end_session_endpoint' expression for the Keycloak realm.
@@ -88,18 +112,18 @@ public sealed class KeycloakRealmResource(string name, string realmName, Keycloa
88
112
/// <summary>
89
113
/// Gets or sets the 'registration_endpoint' for the Keycloak realm.
90
114
/// </summary>
91
- public string RegistrationEndpoint { get ; set ; } = "clients-registrations/openid-connect" ;
115
+ public string RegistrationEndpoint => "clients-registrations/openid-connect" ;
92
116
93
117
/// <summary>
94
118
/// Gets the 'registration_endpoint' expression for the Keycloak realm.
95
119
/// </summary>
96
120
public ReferenceExpression RegistrationEndpointExpression => ReferenceExpression . Create ( $ "{ ConnectionStringExpression } { RegistrationEndpoint } ") ;
97
121
98
122
/// <inheritdoc/>
99
- public KeycloakResource Parent { get ; } = parent ;
123
+ public KeycloakResource Parent { get ; }
100
124
101
125
/// <summary>
102
126
/// Gets the name of the realm.
103
127
/// </summary>
104
- public string RealmName { get ; } = realmName ;
128
+ public string RealmName { get ; }
105
129
}
0 commit comments