pub struct AuthenticatedCaller(pub Option<RequestContext>);Expand description
The authenticated principal of a request, read from the request extensions.
The server’s authentication layer stores the extracted identity as an
Option<RequestContext> extension; middleware written outside this crate
can also store a bare RequestContext. This extractor accepts either and
never rejects: it yields None when no authentication ran, which is how a
handler tells an unauthenticated deployment from an authenticated caller.
§Example
use adk_server::auth_bridge::AuthenticatedCaller;
async fn whoami(AuthenticatedCaller(caller): AuthenticatedCaller) -> String {
caller.map_or_else(|| "anonymous".to_string(), |context| context.user_id)
}
let _app: axum::Router = axum::Router::new().route("/whoami", axum::routing::get(whoami));Tuple Fields§
§0: Option<RequestContext>Implementations§
Trait Implementations§
Source§impl Clone for AuthenticatedCaller
impl Clone for AuthenticatedCaller
Source§impl Debug for AuthenticatedCaller
impl Debug for AuthenticatedCaller
Source§impl Default for AuthenticatedCaller
impl Default for AuthenticatedCaller
Source§impl<S: Send + Sync> FromRequestParts<S> for AuthenticatedCaller
impl<S: Send + Sync> FromRequestParts<S> for AuthenticatedCaller
Auto Trait Implementations§
impl Freeze for AuthenticatedCaller
impl RefUnwindSafe for AuthenticatedCaller
impl Send for AuthenticatedCaller
impl Sync for AuthenticatedCaller
impl Unpin for AuthenticatedCaller
impl UnsafeUnpin for AuthenticatedCaller
impl UnwindSafe for AuthenticatedCaller
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.