@@ -108,6 +108,20 @@ impl Context {
108108 }
109109 }
110110
111+ /// Returns the ID of the credential used to authenticate, if any.
112+ ///
113+ /// For session auth, this is the session ID. For access token auth, this is
114+ /// the token ID. For SCIM auth, this is the SCIM token ID.
115+ /// Not set for spoof auth, built-in users, or unauthenticated requests.
116+ pub fn credential_id ( & self ) -> Option < Uuid > {
117+ match & self . kind {
118+ Kind :: Authenticated ( Details { credential_id, .. } , ..) => {
119+ * credential_id
120+ }
121+ Kind :: Unauthenticated => None ,
122+ }
123+ }
124+
111125 /// Returns the current actor's Silo if they have one or an appropriate
112126 /// error otherwise
113127 ///
@@ -234,6 +248,7 @@ impl Context {
234248 Details {
235249 actor : Actor :: UserBuiltin { user_builtin_id } ,
236250 device_token_expiration : None ,
251+ credential_id : None ,
237252 } ,
238253 None ,
239254 ) ,
@@ -253,6 +268,7 @@ impl Context {
253268 silo_id : USER_TEST_PRIVILEGED . silo_id ,
254269 } ,
255270 device_token_expiration : None ,
271+ credential_id : None ,
256272 } ,
257273 Some ( SiloAuthnPolicy :: try_from ( & * DEFAULT_SILO ) . unwrap ( ) ) ,
258274 ) ,
@@ -283,6 +299,7 @@ impl Context {
283299 Details {
284300 actor : Actor :: SiloUser { silo_user_id, silo_id } ,
285301 device_token_expiration : None ,
302+ credential_id : None ,
286303 } ,
287304 Some ( silo_authn_policy) ,
288305 ) ,
@@ -298,6 +315,7 @@ impl Context {
298315 Details {
299316 actor : Actor :: Scim { silo_id } ,
300317 device_token_expiration : None ,
318+ credential_id : None ,
301319 } ,
302320 // This should never be non-empty, we don't want the SCIM user
303321 // to ever have associated roles.
@@ -415,12 +433,15 @@ enum Kind {
415433#[ derive( Clone , Debug , Deserialize , Serialize ) ]
416434pub struct Details {
417435 /// the actor performing the request
418- actor : Actor ,
436+ pub actor : Actor ,
419437 /// When the device token expires. Present only when authenticating via
420438 /// a device token. This is a slightly awkward fit but is included here
421439 /// because we need to use this to clamp the expiration time when device
422440 /// tokens are confirmed using an existing device token.
423- device_token_expiration : Option < DateTime < Utc > > ,
441+ pub device_token_expiration : Option < DateTime < Utc > > ,
442+ /// ID of the credential used to authenticate (session ID, access token ID,
443+ /// or SCIM token ID). Not set for spoof auth or built-in users.
444+ pub credential_id : Option < Uuid > ,
424445}
425446
426447/// Who is performing an operation
0 commit comments