Skip to content

Commit a872c6b

Browse files
committed
sentry middlewares for analytics:
- authenticate_as_advertiser - authenticate_as_publisher
1 parent 4bc5a18 commit a872c6b

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

sentry/src/middleware/auth.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use hyper::{
99
use redis::aio::MultiplexedConnection;
1010

1111
use adapter::{prelude::*, primitives::Session as AdapterSession, Adapter};
12-
use primitives::ValidatorId;
12+
use primitives::{analytics::AuthenticateAs, ValidatorId};
1313

1414
use crate::{middleware::Middleware, response::ResponseError, Application, Auth, Session};
1515

@@ -181,6 +181,42 @@ pub async fn authenticate<C: Locked + 'static, B>(
181181
Ok(next.run(request).await)
182182
}
183183

184+
pub async fn authenticate_as_advertiser<B>(
185+
mut request: axum::http::Request<B>,
186+
next: Next<B>,
187+
) -> Result<axum::response::Response, ResponseError> {
188+
let auth_uid = request
189+
.extensions()
190+
.get::<Auth>()
191+
.ok_or(ResponseError::Unauthorized)?
192+
.uid;
193+
194+
request
195+
.extensions_mut()
196+
.insert(AuthenticateAs::Advertiser(auth_uid))
197+
.expect("Should not contain previous value of AuthenticateAs");
198+
199+
Ok(next.run(request).await)
200+
}
201+
202+
pub async fn authenticate_as_publisher<B>(
203+
mut request: axum::http::Request<B>,
204+
next: Next<B>,
205+
) -> Result<axum::response::Response, ResponseError> {
206+
let auth_uid = request
207+
.extensions()
208+
.get::<Auth>()
209+
.ok_or(ResponseError::Unauthorized)?
210+
.uid;
211+
212+
request
213+
.extensions_mut()
214+
.insert(AuthenticateAs::Publisher(auth_uid))
215+
.expect("Should not contain previous value of AuthenticateAs");
216+
217+
Ok(next.run(request).await)
218+
}
219+
184220
/// Check `Authorization` header for `Bearer` scheme with `Adapter::session_from_token`.
185221
/// If the `Adapter` fails to create an `AdapterSession`, `ResponseError::BadRequest` will be returned.
186222
async fn for_request<C: Locked>(

0 commit comments

Comments
 (0)