package token import "time" const ( SessionTTL = 12 * time.Hour // revokedTombstoneTTL outlives any cached copy, so no fill can resurrect a revoked session. revokedTombstoneTTL = SessionTTL RefreshTokenTTL = 12 * time.Hour AccessTokenLifeTime = 12 * time.Hour RefreshTokenLifeTime = 180 * 24 * time.Hour AuthProviderEmail = "email" AuthProviderApple = "apple" AuthProviderGoogle = "google" AuthProviderWebAuthn = "webauthn" // AuthProviderOIDC covers generic single sign-on. Google and Apple keep // their own values, so the security page can name what was actually used. AuthProviderOIDC = "oidc" ) // Token purposes. Every JWT this service signs carries one, and each verifier // requires the purpose it expects. // // Without it, all of these tokens were interchangeable: they share one signing // key and one claim shape, so a password-reset link token or the challenge // token issued after a password but before the emailed code would open a // websocket and stream a workspace's events. The Go side was safe only because // each token is separately bound to a nonce in Redis or a row in `sessions`; // the realtime service checks neither, and had nothing else to go on. const ( PurposeAccess = "access" PurposeRefresh = "refresh" PurposeWebSocket = "ws" PurposeWebSocketProxy = "ws_proxy" PurposeLoginCode = "login" PurposeRegistration = "registration" PurposePasswordReset = "reset" PurposeTwoFAPending = "2fa" // PurposeSSOLink is a federated sign-in parked on an existing password // account until that password is presented; it opens nothing else. PurposeSSOLink = "sso_link" // PurposeInitialPassword lets the holder of an issued initial password choose their own; it opens nothing else. PurposeInitialPassword = "initial_password" // A session signed in on an agency portal carries these instead of access, refresh and ws, so a release // that does not hold such a session to its agency refuses its tokens rather than serving them unrestricted. PurposePortalAccess = "portal_access" PurposePortalRefresh = "portal_refresh" PurposePortalWebSocket = "portal_ws" ) // accessPurpose, refreshPurpose and WebSocketPurpose name what a session's tokens carry: the portal // purposes exactly when the session is bound to an agency portal. func accessPurpose(portal bool) string { if portal { return PurposePortalAccess } return PurposeAccess } func refreshPurpose(portal bool) string { if portal { return PurposePortalRefresh } return PurposeRefresh } func WebSocketPurpose(portal bool) string { if portal { return PurposePortalWebSocket } return PurposeWebSocket }