fedimint_server_core/
net.rs

1use fedimint_core::module::{ApiEndpointContext, ApiError, ApiResult};
2
3/// A token proving the the API call was authenticated
4///
5/// Api handlers are encouraged to take it as an argument to avoid sensitive
6/// guardian-only logic being accidentally unauthenticated.
7pub struct GuardianAuthToken {
8    _marker: (), // private field just to make creating it outside impossible
9}
10
11impl GuardianAuthToken {
12    /// Creates a token without verifying authentication.
13    ///
14    /// # Safety
15    /// The caller must ensure that authentication has already been verified
16    /// through other means before calling this function.
17    pub fn new_unchecked() -> Self {
18        GuardianAuthToken { _marker: () }
19    }
20}
21
22pub fn check_auth(context: &mut ApiEndpointContext) -> ApiResult<GuardianAuthToken> {
23    if context.has_auth() {
24        Ok(GuardianAuthToken { _marker: () })
25    } else {
26        Err(ApiError::unauthorized())
27    }
28}