Skip to content

How to identify Session ID in AWS Cognito JWT tokens

0

Does AWS Cognito provides any sid (Session ID in OIDC) like claim in JWT Access Token to know about logged in session ? If not, how we can track logged in session via claims if any such identifier is present or some other suggested alternative ?

asked a month ago118 views

1 Answer
0
Accepted Answer

Amazon Cognito doesn't provide the standard OIDC sid claim in its access or ID tokens by default.

If your goal is to identify the individual JWT, you can use the jti claim. However, jti identifies a token, not the whole login session.

For tracking a login session, origin_jti is usually more useful. When token revocation is enabled, Cognito adds both jti and origin_jti to access and ID tokens. Tokens issued from the same refresh-token session are associated through the original token identifier, and revoking that refresh token invalidates the tokens generated from that session without affecting the user's other refresh-token sessions.

So, roughly:

  • sub → identifies the user
  • jti → identifies an individual JWT
  • origin_jti → useful for identifying/tracking the refresh-token session
  • auth_time → tells you when the user authenticated

If you specifically require an application-defined sid, another option is to generate your own session identifier and add it as a custom claim using a Pre Token Generation Lambda trigger. Cognito supports adding custom claims to access and ID tokens through this trigger.

For most Cognito applications, I would use origin_jti together with sub rather than expecting an OIDC sid claim.

answered a month ago

EXPERT

reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.