@@ -9,7 +9,7 @@ use hyper::{
9
9
use redis:: aio:: MultiplexedConnection ;
10
10
11
11
use adapter:: { prelude:: * , primitives:: Session as AdapterSession , Adapter } ;
12
- use primitives:: ValidatorId ;
12
+ use primitives:: { analytics :: AuthenticateAs , ValidatorId } ;
13
13
14
14
use crate :: { middleware:: Middleware , response:: ResponseError , Application , Auth , Session } ;
15
15
@@ -181,6 +181,42 @@ pub async fn authenticate<C: Locked + 'static, B>(
181
181
Ok ( next. run ( request) . await )
182
182
}
183
183
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
+
184
220
/// Check `Authorization` header for `Bearer` scheme with `Adapter::session_from_token`.
185
221
/// If the `Adapter` fails to create an `AdapterSession`, `ResponseError::BadRequest` will be returned.
186
222
async fn for_request < C : Locked > (
0 commit comments