@@ -7,6 +7,7 @@ public sealed class AuthorizePage : PageModel
77
88 private readonly ITokenCollection _tokenCollection ;
99 private readonly IRealmCollection _realmCollection ;
10+ private readonly IClientCollection _clientCollection ;
1011 private readonly IRealmProvider _realmProvider ;
1112
1213 #region constructors
@@ -15,13 +16,15 @@ public AuthorizePage(
1516 IUserCollection userCollection ,
1617 IRealmProvider realmProvider ,
1718 IRealmCollection realmCollection ,
18- ITokenCollection tokenCollection )
19+ ITokenCollection tokenCollection ,
20+ IClientCollection clientCollection )
1921 {
2022 _dispatcher = dispatcher ;
2123 _userCollection = userCollection ;
2224 _realmCollection = realmCollection ;
2325 _realmProvider = realmProvider ;
2426 _tokenCollection = tokenCollection ;
27+ _clientCollection = clientCollection ;
2528 }
2629 #endregion
2730
@@ -33,12 +36,29 @@ public AuthorizePage(
3336
3437 public async Task < IActionResult > OnGetAsync ( )
3538 {
36- var filters = RealmFilters . WithSpecifications ( )
39+ var filters = ClientFilters . WithSpecifications ( )
3740 . WithClientId ( Parameters . ClientId )
3841 . Build ( ) ;
3942
40- var realms = await _realmCollection . GetRealmsAsync ( filters ) ;
41- var realm = realms . FirstOrDefault ( ) ;
43+ var clients = await _clientCollection . GetClientsAsync ( filters ) ;
44+ var client = clients . FirstOrDefault ( ) ;
45+
46+ if ( client is null )
47+ {
48+ ModelState . AddModelError (
49+ key : ClientErrors . ClientDoesNotExist . Code ,
50+ errorMessage : ClientErrors . ClientDoesNotExist . Description
51+ ) ;
52+
53+ return Page ( ) ;
54+ }
55+
56+ var realmFilters = RealmFilters . WithSpecifications ( )
57+ . WithIdentifier ( client . RealmId )
58+ . Build ( ) ;
59+
60+ var realms = await _realmCollection . GetRealmsAsync ( realmFilters ) ;
61+ var realm = realms . First ( ) ;
4262
4363 if ( realm is null )
4464 {
@@ -71,7 +91,11 @@ public async Task<IActionResult> OnPostAsync()
7191 var result = await _dispatcher . DispatchAsync ( Credentials ) ;
7292 if ( result . IsFailure )
7393 {
74- ModelState . AddModelError ( result . Error . Code , result . Error . Description ) ;
94+ ModelState . AddModelError (
95+ key : result . Error . Code ,
96+ errorMessage : result . Error . Description
97+ ) ;
98+
7599 return Page ( ) ;
76100 }
77101
@@ -86,7 +110,11 @@ public async Task<IActionResult> OnPostAsync()
86110
87111 if ( user is null )
88112 {
89- ModelState . AddModelError ( AuthenticationErrors . UserNotFound . Code , AuthenticationErrors . UserNotFound . Description ) ;
113+ ModelState . AddModelError (
114+ key : AuthenticationErrors . UserNotFound . Code ,
115+ errorMessage : AuthenticationErrors . UserNotFound . Description
116+ ) ;
117+
90118 return Page ( ) ;
91119 }
92120
0 commit comments