@@ -39,6 +39,7 @@ ITokenService tokenService
3939 // GET /api/users/me
4040 // GET /api/users/reauthenticate
4141 // GET /api/users/accept-license?catalogId=X
42+ // GET /api/users/tokens
4243 // POST /api/users/tokens/create
4344 // DELETE /api/users/tokens/{tokenId}
4445
@@ -51,8 +52,6 @@ ITokenService tokenService
5152 // POST /api/users/{userId}/claims
5253 // DELETE /api/users/claims/{claimId}
5354
54- // GET /api/users/{userId}/tokens
55-
5655 private readonly IDBService _dbService = dBService ;
5756
5857 private readonly ITokenService _tokenService = tokenService ;
@@ -126,27 +125,9 @@ public async Task<ActionResult<MeResponse>> GetMeAsync()
126125 if ( user is null )
127126 return NotFound ( $ "Could not find user { userId } .") ;
128127
129- var translatedClaimsMap = user . Claims
130- . ToDictionary ( entry => entry . Id , entry => new NexusClaim (
131- id : default ,
132- type : entry . Type ,
133- value : entry . Value
134- ) ) ;
135-
136- var tokenMap = await _tokenService . GetAllAsync ( userId ) ;
137-
138- var translatedTokenMap = tokenMap
139- . ToDictionary ( entry => entry . Value . Id , entry => new PersonalAccessToken (
140- entry . Value . Description ,
141- entry . Value . Expires ,
142- entry . Value . Claims
143- ) ) ;
144-
145128 return new MeResponse (
146129 user . Id ,
147- user . Name ,
148- translatedClaimsMap ,
149- translatedTokenMap
130+ user
150131 ) ;
151132 }
152133
@@ -192,6 +173,41 @@ .. Enum.GetNames<NexusClaims>(),
192173 return Redirect ( "/" ) ;
193174 }
194175
176+ /// <summary>
177+ /// Gets all personal access tokens.
178+ /// </summary>
179+ /// <param name="userId">The optional user identifier. If not specified, the current user will be used.</param>
180+ [ Authorize ( AuthenticationSchemes = CookieAuthenticationDefaults . AuthenticationScheme ) ]
181+ [ HttpGet ( "tokens" ) ]
182+ public async Task < ActionResult < IReadOnlyDictionary < Guid , PersonalAccessToken > > > GetTokensAsync (
183+ [ FromQuery ] string ? userId = default
184+ )
185+ {
186+ if ( TryAuthenticate ( userId , out var actualUserId , out var response ) )
187+ {
188+ var user = await _dbService . FindUserAsync ( actualUserId ) ;
189+
190+ if ( user is null )
191+ return NotFound ( $ "Could not find user { userId } .") ;
192+
193+ var tokenMap = await _tokenService . GetAllAsync ( actualUserId ) ;
194+
195+ var translatedTokenMap = tokenMap
196+ . ToDictionary ( entry => entry . Value . Id , entry => new PersonalAccessToken (
197+ entry . Value . Description ,
198+ entry . Value . Expires ,
199+ entry . Value . Claims
200+ ) ) ;
201+
202+ return translatedTokenMap ;
203+ }
204+
205+ else
206+ {
207+ return response ;
208+ }
209+ }
210+
195211 /// <summary>
196212 /// Creates a personal access token.
197213 /// </summary>
@@ -402,32 +418,6 @@ public async Task<ActionResult> DeleteClaimAsync(
402418 return Ok ( ) ;
403419 }
404420
405- /// <summary>
406- /// Gets all personal access tokens.
407- /// </summary>
408- /// <param name="userId">The identifier of the user.</param>
409- [ Authorize ( Policy = NexusPolicies . RequireAdmin ) ]
410- [ HttpGet ( "{userId}/tokens" ) ]
411- public async Task < ActionResult < IReadOnlyDictionary < Guid , PersonalAccessToken > > > GetTokensAsync (
412- string userId )
413- {
414- var user = await _dbService . FindUserAsync ( userId ) ;
415-
416- if ( user is null )
417- return NotFound ( $ "Could not find user { userId } .") ;
418-
419- var tokenMap = await _tokenService . GetAllAsync ( userId ) ;
420-
421- var translatedTokenMap = tokenMap
422- . ToDictionary ( entry => entry . Value . Id , entry => new PersonalAccessToken (
423- entry . Value . Description ,
424- entry . Value . Expires ,
425- entry . Value . Claims
426- ) ) ;
427-
428- return translatedTokenMap ;
429- }
430-
431421 private bool TryAuthenticate (
432422 string ? requestedId ,
433423 out string userId ,
0 commit comments