@@ -60,7 +60,7 @@ public static WebApplication MapSessionEndpoints(this WebApplication app, ApiVer
6060 . MapToApiVersion ( apiVersion1 )
6161 . RequirePermission ( AccessPermissions . Sessions . View ) ;
6262
63- app . MapPost ( "/v{version:apiVersion}/sessions" , async ( HttpContext httpContext , IOptions < AccessOptions > accessOptions , ISessionCache sessionCache , IMediator mediator , IDatabaseContextFactory databaseContextFactory , [ FromBody ] Messages . v1 . RegisterSession message ) =>
63+ app . MapPost ( "/v{version:apiVersion}/sessions" , async ( ILogger < RegisterSession > logger , HttpContext httpContext , IOptions < AccessOptions > accessOptions , ISessionCache sessionCache , IMediator mediator , IDatabaseContextFactory databaseContextFactory , [ FromBody ] Messages . v1 . RegisterSession message ) =>
6464 {
6565 var options = Guard . AgainstNull ( accessOptions . Value ) ;
6666
@@ -71,7 +71,7 @@ public static WebApplication MapSessionEndpoints(this WebApplication app, ApiVer
7171
7272 if ( string . IsNullOrWhiteSpace ( message . IdentityName ) )
7373 {
74- return Results . BadRequest ( ) ;
74+ return Results . BadRequest ( Resources . SessionIdentityNameRequired ) ;
7575 }
7676
7777 var registerSession = new RegisterSession ( message . IdentityName ) ;
@@ -92,9 +92,16 @@ public static WebApplication MapSessionEndpoints(this WebApplication app, ApiVer
9292 {
9393 var identityId = httpContext . GetIdentityId ( ) ;
9494
95- if ( ! identityId . HasValue || ! await sessionCache . HasPermissionAsync ( identityId . Value , AccessPermissions . Sessions . Register ) )
95+ if ( ! identityId . HasValue )
9696 {
97- return Results . BadRequest ( ) ;
97+ return Results . BadRequest ( Resources . HttpContextIdentityNotFound ) ;
98+ }
99+
100+ if ( ! await sessionCache . HasPermissionAsync ( identityId . Value , AccessPermissions . Sessions . Register ) )
101+ {
102+ logger . LogDebug ( $ "[UNAUTHORIZED] : identity id = '{ identityId . Value } ' / permission = '{ AccessPermissions . Sessions . Register } '") ;
103+
104+ return Results . Unauthorized ( ) ;
98105 }
99106 }
100107
0 commit comments