pub struct Auth {
pub sub: String,
pub preferred_username: Option<String>,
pub name: Option<String>,
pub email: Option<String>,
pub realm_roles: Vec<String>,
pub claims: HashMap<String, Value>,
}Expand description
Authenticated user context, validated by the Cufflink platform.
The platform validates the JWT token (via Keycloak) and extracts claims
before passing them to your handler. You never need to validate tokens
yourself — the auth field is only present when the token is valid.
ⓘ
handler!(protected, |req: Request| {
let auth = match req.require_auth() {
Ok(auth) => auth,
Err(resp) => return resp,
};
if !auth.has_role("admin") {
return Response::error("Forbidden");
}
Response::json(&json!({"user": auth.sub}))
});Fields§
§sub: StringKeycloak subject ID (unique user identifier).
preferred_username: Option<String>Preferred username from Keycloak.
name: Option<String>Display name.
email: Option<String>Email address.
realm_roles: Vec<String>Realm roles assigned to the user in Keycloak.
claims: HashMap<String, Value>All other JWT claims (custom Keycloak mappers, resource_access, etc.).
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Auth
impl RefUnwindSafe for Auth
impl Send for Auth
impl Sync for Auth
impl Unpin for Auth
impl UnsafeUnpin for Auth
impl UnwindSafe for Auth
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