identity: add proxy controller
This commit is contained in:
		
							parent
							
								
									727f2f6ba2
								
							
						
					
					
						commit
						b95fb76cd4
					
				
					 9 changed files with 446 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
using Foxchat.Core;
 | 
			
		||||
using Foxchat.Identity.Database;
 | 
			
		||||
using Foxchat.Identity.Utils;
 | 
			
		||||
using NodaTime;
 | 
			
		||||
 | 
			
		||||
namespace Foxchat.Identity.Middleware;
 | 
			
		||||
| 
						 | 
				
			
			@ -21,10 +22,10 @@ public class ClientAuthorizationMiddleware(
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        var token = ctx.GetToken();
 | 
			
		||||
        if (token == null || token.Expires > clock.GetCurrentInstant())
 | 
			
		||||
        if (token == null || token.Expires < clock.GetCurrentInstant())
 | 
			
		||||
            throw new ApiError.Unauthorized("This endpoint requires an authenticated user.");
 | 
			
		||||
        if (attribute.Scopes.Length > 0 && attribute.Scopes.Except(token.Scopes).Any())
 | 
			
		||||
            throw new ApiError.Forbidden("This endpoint requires ungranted scopes.", attribute.Scopes.Except(token.Scopes));
 | 
			
		||||
        if (attribute.Scopes.Length > 0 && attribute.Scopes.Except(token.ExpandScopes()).Any())
 | 
			
		||||
            throw new ApiError.Forbidden("This endpoint requires ungranted scopes.", attribute.Scopes.Except(token.ExpandScopes()));
 | 
			
		||||
 | 
			
		||||
        await next(ctx);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue