Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

JSON Web Tokens (JWT)

Configure JSON Web Token authentication so users can sign in to Synap from an external identity provider or login page.

JSON Web Token authentication lets users sign in to Synap through your own login page or identity provider. Your server creates a signed token containing the user's identity, then redirects the user's browser to Synap.

Synap verifies the token and either signs in an existing user or creates a new account. The user is then redirected to the selected Synap portal with an active session.

JWT authentication is available on plans that include single sign-on. Contact your Synap account manager or Synap Support to enable it.

Before you begin

Each Synap portal has its own JWT configuration. You will need:

  • The External Authentication ID (eaid) for the portal.

  • The signing secret for that eaid.

  • A server-side application that can authenticate the user, construct the JWT and redirect their browser.

Keep the signing secret on your server. Do not expose it in client-side code, include it in a browser application or commit it to source control.

If you use several separate Synap portals, choose the destination portal before constructing the token. Use that portal's eaid and signing secret.

Redirect the user to Synap

After authenticating the user, redirect their browser to the appropriate endpoint. This must be a browser redirect, not a server-to-server request, because the response establishes the user's browser session.

Authentication endpoints

EU infrastructure:

https://api.synap.ac/external-auth/jwt/authenticate?jwt=YOUR_JWT_TOKEN

US infrastructure:

Use the endpoint supplied for your portal if you are unsure which region applies.

Query parameters

Parameter
Description
Designation

jwt

The signed and URL-encoded JSON Web Token.

Required

return_to

A URL-encoded, fully qualified URL representing the page to open after authentication. Synap uses its path and query string on the selected portal and ignores its host. If omitted, the user is sent to the portal home page.

Optional

error_url

A URL-encoded base URL used when authentication fails. Synap appends /login and an sso_error query parameter containing a user-readable message. If omitted, the user is sent to the Synap login page.

Optional

For example, a return_to value of https://example.com/collections/abc123?tab=overview opens /collections/abc123?tab=overview on the Synap portal selected by eaid.

Construct the JWT

Sign tokens with HMAC SHA-256 (HS256):

Payload

A recommended payload is:

Calculate exp when creating each token. The example value is only illustrative.

Claim
Description
Designation

eaid

The External Authentication ID for the destination portal. Use the signing secret belonging to the same configuration.

Required

sub

A stable, non-empty identifier for the user in your identity system. Either sub or email must be supplied.

Conditionally required

email

The user's email address. Either email or sub must be supplied. Include both when possible.

Conditionally required

name

The user's full name. If omitted, a placeholder name is used when creating the account.

Recommended

exp

The token expiry as Unix time in seconds. Use a short lifetime, such as 5 to 10 minutes.

Strongly recommended

subPortal

The ID of a Synap Subportal. Omit this when using a standard portal or when selecting between separate portals with eaid.

Optional

userGroup

The ID of a user group belonging to the destination portal. Synap adds the user to this group during authentication. Existing group memberships are not removed.

Optional

targetLinkUri

A supported Synap collection launch URL. See Launch a collection.

Optional

At least one of sub or email must be present. For the most reliable account matching, provide both and keep sub stable for the lifetime of the user's account.

Additional claims do not cause authentication to fail, but the JWT authentication flow does not interpret them. A supported claim with an invalid type or value can cause authentication to fail.

Expiry format

JWT expiry uses NumericDate format: the number of seconds since 1 January 1970 UTC. Do not supply a timestamp in milliseconds.

For example, in JavaScript you can create an expiry five minutes in the future with:

Signature

Construct the signature using the secret belonging to the token's eaid:

How users are matched

When sub is present, Synap uses it as the user's primary external identity for that JWT configuration. If no linked account is found and the token also contains an email address, Synap looks for an account with that email in the destination portal and links it to the external identity.

When sub is omitted, the normalized email address is used as the external identity.

Use a stable identifier from your identity provider for sub, such as an Auth0 subject. Changing sub can prevent Synap from finding the existing external identity. The same sub can safely be used across separate Synap portals because each portal has a different JWT configuration.

Add the user to a group

Set userGroup to the Synap object ID of a group in the destination portal:

Synap adds both new and existing users to the group during authentication. This is additive: omitting the claim on a later login does not remove the user from the group.

Launch a collection

Use targetLinkUri when the user should open a specific collection immediately after authentication:

The supported format is:

Synap checks that the user can access the collection before completing the launch. If userGroup is also supplied, the group membership is added before this access check.

targetLinkUri takes precedence over the return_to query parameter. For other pages within Synap, use return_to instead.

Testing and troubleshooting

You can use JWT.io to inspect a token during development. Do not paste production tokens or signing secrets into third-party debugging tools.

If authentication fails, check that:

  • The token is signed with HS256 using the secret for the supplied eaid.

  • The secret was not base64 encoded before signing.

  • exp is expressed in seconds and has not passed.

  • At least one of sub or email is present.

  • email is valid when supplied.

  • userGroup, subPortal and collection IDs belong to the destination portal.

  • The authentication endpoint matches the region used by the portal.

Most server-side JWT libraries can construct and sign the token. See the JWT library list for options by language and framework.

Last updated

Was this helpful?