Repository navigation
19.4.0
Customer identity: Gleap.setUserJwt(_:) identifies the user with one HS256 JWT signed by your backend. The SDK reads userId (or user_id) from the payload without checking the signature and sends the identify with the token as the user hash and no other contact fields; a token that is not three base64url parts, has no user id or is longer than 4096 characters is refused with a log line and nothing is sent. The token stays in memory only and is sent again whenever it says something new (another claim or key), even when nothing else did; a token re-minted for the same user and data (only iat/exp/nbf/jti differ) is not sent again. Gleap.setUserJwtProvider(_:) fetches a fresh token when the server answers token_expired (the identify is retried once) and before a file access renewal when the token expires within 5 minutes; one call at a time, 10 second timeout, 30 second pause after a failure. An identify refused with token_expired or token_invalid keeps the identity and the session (a warning is logged); signature_required and other refusals start over as a guest as before (signature_required now logs why). Gleap.setAuthTokens(_:) stores per-user tokens for API tools on the signed contact (POST /sessions/auth-tokens, NSNull removes one), keeps them in memory and sends them again after a signed identify on a new session. clearIdentity drops the token and the auth tokens; the provider stays.
Signed sessions: a signed identify (identity token or user hash) answers with a grant (identity.grant), the server-signed session credential. The SDK keeps it in memory and in NSUserDefaults next to gleapId / gleapHash with its expiry, so an app restart stays signed until it expires, and sends it as the Gleap-Grant header on every request of the session it was issued to (session, identify, contact updates, events, reports, uploads, capture). The Messenger gets it as a top-level grant field of session-update, sent again whenever it changes. An identify answered without a grant drops it, clearIdentity drops it, and a grant about to expire is renewed by sending the last signed identify again (through the JWT provider when the token is about to expire too), at most once a minute and on return to the foreground. An identify refused with identity_mismatch (the session belongs to another user) drops the local session, starts a fresh visitor session and sends the identify once more; a second mismatch starts over as a guest. New: Gleap.setSessionDuration(_:) (milliseconds) caps the grant's lifetime and is sent with every identify.
Returning users and short sessions: when the session answer says the project runs Signed (identity.mode: 'signed') and the identified session has no grant, the app's held identify (its user hash or token) is sent once per app launch and session even when nothing changed, so a returning user gets a grant; it is never repeated in a loop, and a refusal of that identify keeps the session. A grant is renewed at min(5 minutes, half its lifetime) before it expires, and a renewal held back by the once-a-minute limit runs once the minute is over. The JWT provider returning an expired token, or the token the server just refused, counts as a failure (30 second pause). The Messenger web view no longer leaves the Messenger origin (other main frame navigations open in Safari, as on Android), and session updates and other messages are only evaluated on a page of the Messenger origin.
Retries: an identify that gets no answer (offline, a server failure, 408 or 429) is sent again after 1 and 2 seconds and then on return to the foreground, and the signed identify for a returning user only counts as sent once the server answers, so a user who launches offline still gets a grant. A session answer without a grant while the SDK holds one (the server rejected it, for example after a secret rotation) drops it from memory and NSUserDefaults and sends the held identify once for a new grant. A grant renewal that fails is tried again every 60 seconds while the app is active, so the grant does not lapse mid-session.