@@ -3,19 +3,24 @@ use async_trait::async_trait;
33use std:: collections:: HashMap ;
44use std:: string:: ToString ;
55
6+ /// Response returned for Authorizer request if user is authenticated and authorized.
67#[ derive( Debug , Clone ) ]
78pub struct AuthResponse {
9+ /// A `user_token` identifying the authenticated and authorized user.
810 pub user_token : String ,
911}
1012
11- // Interface for authorizer that is run before every request.
13+ /// Interface for authorizer that is run before executing every request.
1214#[ async_trait]
1315pub trait Authorizer : Send + Sync {
16+ /// Verifies authentication and authorization based on request headers.
17+ /// Returns [`AuthResponse`] for an authenticated and authorized user or [`VssError::AuthError`]
18+ /// for an unauthorized request.
1419 async fn verify ( & self , headers_map : & HashMap < String , String > )
1520 -> Result < AuthResponse , VssError > ;
1621}
1722
18- // A no-operation authorizer, that lets any user-request go through.
23+ /// A no-operation authorizer, which lets any user-request go through.
1924pub struct NoopAuthorizer { }
2025
2126const UNAUTHENTICATED_USER : & str = "unauth-user" ;
@@ -25,6 +30,6 @@ impl Authorizer for NoopAuthorizer {
2530 async fn verify (
2631 & self , _headers_map : & HashMap < String , String > ,
2732 ) -> Result < AuthResponse , VssError > {
28- Ok ( AuthResponse { user_token : UNAUTHENTICATED_USER . to_string ( ) . clone ( ) } )
33+ Ok ( AuthResponse { user_token : UNAUTHENTICATED_USER . to_string ( ) } )
2934 }
3035}
0 commit comments