Signing in a user ties them to their feedback items. Gleap stores a unique user ID and optional meta information such as email & name on the contact.
Sign in your users
Sign your users in with an identity token: a short JWT that your backend signs for the logged-in user. Gleap checks the token once and answers with a session grant that the SDK sends with every later request. Everything in the token is signed: the user ID, the email, the name, the company and any attribute you add, such as stripeCustomerId.
Create an identity key in Settings → Security → Customer identity → Identity keys. Keep its secret on your server.
After login, your backend signs a token for the user with that key.
Your app passes the token to
setUserJwtafter login and on every app start.Once a token from your backend checks out, click Turn on next to Turn on signed sessions in Settings → Security → Customer identity, then confirm with Turn on. Creating a key alone doesn't protect any fields or change how Gleap treats your users.
Sign the token on your backend, for example in Node.js:
// npm install jsonwebtoken
const jwt = require("jsonwebtoken");
const token = jwt.sign(
{
userId: String(user.id),
email: user.email,
name: user.name,
company: { id: user.companyId, name: user.companyName },
},
process.env.GLEAP_IDENTITY_SECRET,
{ algorithm: "HS256", keyid: process.env.GLEAP_IDENTITY_KEY_ID, expiresIn: "30m" }
);Sign the token on your backend lists every claim and shows PHP, Python, Ruby, C# and Go. Return the token to your app, for example in the login response or from an endpoint such as /api/gleap-token.
Then sign the user in from your app:
Gleap.getInstance().setUserJwt(token);
// Optional: fetch a fresh token for renewal (pass null when it failed)
Gleap.getInstance().setUserJwtProvider(callback ->
myBackend.fetchGleapToken(token -> callback.onToken(token))
);Gleap.getInstance().setUserJwt(token)
// Optional: fetch a fresh token for renewal (pass null when it failed)
Gleap.getInstance().setUserJwtProvider(GleapUserJwtProvider { callback ->
myBackend.fetchGleapToken { token -> callback.onToken(token) }
})The token names the user and carries the contact data, so you don't need a separate identifyContact call. setUserJwt and setUserJwtProvider need 19.4.0 or newer. setUserJwtProvider is optional: the SDK calls it for a fresh token when the session grant is about to run out or a token was refused as expired. From 19.5.0 the provider also restores the signed session after an app restart when no grant is held. We still recommend calling setUserJwt on every app start.
Calling setUserJwt again with a token for the same user and data sends nothing new: the SDK keeps the session grant and only signs in again when the claims change or the grant has run out. The session grant lasts as long as Signed login lasts (7 days by default); the token's exp (for example 30 minutes) only gates the sign-in.
When the grant runs out and no fresh token arrives, the user stays identified but unsigned until the next setUserJwt or provider token: the widget shows their last 14 days of conversations and protected fields keep their values. Set setUserJwtProvider so the SDK renews the grant before that happens.
Call Gleap.getInstance().clearIdentity() on logout and before you sign in another user. Gleap.getInstance().setSessionDuration(3600000L) (milliseconds) shortens the signed session; the project's maximum applies.
Moving from an older integration? See Upgrade to identity tokens.
Identify without a token
identifyContact without a token still works, but the contact is unsigned: anyone could claim that user ID. The widget then shows only conversations from the last 14 days, protected fields keep their values, and Gleap refuses the call on platforms (web, iOS, Android) where you turned on Require a signature.
GleapSessionProperties sessionProperties = new GleapSessionProperties();
sessionProperties.setEmail("[email protected]");
sessionProperties.setName("Franzi");
sessionProperties.setPhone("+1 (902) 123123");
sessionProperties.setValue(199.95);
sessionProperties.setPlan("Pro plan");
sessionProperties.setCompanyName("ACME inc.");
sessionProperties.setCompanyId("193948");
sessionProperties.setAvatar("https://.../avatar.png");
JSONObject jsonObject = new JSONObject();
jsonObject.put("key1", "data one");
jsonObject.put("key2", "data two");
sessionProperties.setCustomData(jsonObject);
Gleap.getInstance().identifyContact("user_ID", sessionProperties);Protected conversation files
With Protect new files in Settings → Security → Conversation files (Authenticated conversation files), conversation files can only be opened by agents and by the signed-in customer the conversation belongs to. The SDK (19.4.0 or newer) supports it without extra setup, as long as your app signs the customer in with setUserJwt (see above) on every app start.
A signed-in session gets a short-lived file session (15 minutes). The SDK keeps it in memory only (never on disk), passes it to the widget and renews it automatically before it expires. clearIdentity revokes it.
Email replies link attachments to the first of your App URLs without a *, with a gleapFile query parameter. If your app handles that URL (for example as an App Link), pass the URL that opened the app to Gleap; once the user is signed in, the SDK opens the file's conversation if the user may see it:
Uri link = getIntent().getData();
if (link != null) {
Gleap.getInstance().openProtectedFileFromUrl(link.toString());
}openProtectedFileFromUrl takes the URL as a String and returns false when it has no valid gleapFile parameter. Keep the parameter through your app's login flow.
Update contact properties
Use Gleap.getInstance().updateContact() when contact details change during use, for example when a user subscribes to a new plan or changes their data. It updates the contact in real time. It can't change protected fields: put values you rely on into the token.
GleapSessionProperties sessionProperties = new GleapSessionProperties();
sessionProperties.setPlan("Pro plan");
sessionProperties.setValue(199.95);
Gleap.getInstance().updateContact(sessionProperties);The updateContact method takes in the same contact parameters as the identify method. Partial updates are possible.
GleapSessionProperties sessionProperties = new GleapSessionProperties();
sessionProperties.setEmail("[email protected]");
sessionProperties.setName("Franzi");
sessionProperties.setPhone("+1 (902) 123123");
sessionProperties.setPlan("Pro plan");
sessionProperties.setCompanyName("ACME inc.");
sessionProperties.setCompanyId("193948");
sessionProperties.setAvatar("https://.../avatar.png");
sessionProperties.setValue(199.95);
Gleap.getInstance().updateContact(sessionProperties);Clear the identity on logout
We recommend to clear the identity once the user logs out. Clearing the identity will automatically detach the current session and create a new guest session. It also drops the session grant on this device.
Gleap.getInstance().clearIdentity();Get the identification status of a user
With the following method, you can get the status of the current user identity.
Gleap.getInstance().isUserIdentified();Get the current user identity
With the following method, you can get the current user identity.
Gleap.getInstance().getIdentity();
