web admin panel working well
This commit is contained in:
21
graphs/src/services/mod.rs
Normal file
21
graphs/src/services/mod.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use axum::http::HeaderMap;
|
||||
use tonic::{Request, metadata::MetadataValue};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum AuthenticationError {
|
||||
Missing,
|
||||
Invalid,
|
||||
}
|
||||
|
||||
pub(crate) fn authenticated_request<T>(
|
||||
headers: &HeaderMap,
|
||||
message: T,
|
||||
) -> Result<Request<T>, AuthenticationError> {
|
||||
let token = crate::cookie_value(headers, "analytics_token")
|
||||
.ok_or(AuthenticationError::Missing)?;
|
||||
let value = MetadataValue::try_from(format!("Bearer {token}"))
|
||||
.map_err(|_| AuthenticationError::Invalid)?;
|
||||
let mut request = Request::new(message);
|
||||
request.metadata_mut().insert("authorization", value);
|
||||
Ok(request)
|
||||
}
|
||||
Reference in New Issue
Block a user