Skip to content

Commit 03f082d

Browse files
committed
fixup! Add Authorizer Api with NoopAuthorizer.
1 parent c8b0b8d commit 03f082d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

rust/api/src/auth.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ use async_trait::async_trait;
33
use std::collections::HashMap;
44
use std::string::ToString;
55

6+
/// Response returned for Authorizer request if user is authenticated and authorized.
67
#[derive(Debug, Clone)]
78
pub 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]
1315
pub 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.
1924
pub struct NoopAuthorizer {}
2025

2126
const 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
}

rust/api/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#![deny(rustdoc::private_intra_doc_links)]
1010
#![deny(missing_docs)]
1111

12+
/// Contains interface for authorizer that is run before every request, and its corresponding implementations.
13+
pub mod auth;
1214
/// Implements the error type ([`error::VssError`]) which is eventually converted to [`ErrorResponse`] and returned to client.
1315
///
1416
/// [`ErrorResponse`]: crate::types::ErrorResponse

0 commit comments

Comments
 (0)