Skip to content
  • Workflows
  • Triggers

User post-authentication workflow

Trigger: user:post_authentication

This trigger fires after the user has completed single factor authentication (e.g email + password or Google).

Example use cases

Link to this section

Minimize account sharing

Link to this section

Check previous logins by the user to see if they have carried out impossible travel or if their IP address looks suspicious. Example code

Add properties to a user

Link to this section

Add additional properties to a user before tokens are generated.

Add user to organizations

Link to this section

If the user has been invited to join multiple organizations you can add them as this point, before going through the authorization flow.

Determine if the user is a first time user

Link to this section

Users can be created in multiple ways (imported / API / via the UI / self-registration). This could well be an existing user in your own database, so we tell you if this is a new user from a Kinde perspective. i.e we create a new record so you can act accordingly. Example code

Sign-ins that start from a SAML application

Link to this section

If you use Kinde as a SAML identity provider (workforce identity), this trigger also fires when a user signs in to Kinde to open a SAML application. The workflow runs after the user authenticates and before Kinde returns them to the application.

The workflow only runs when the user actually signs in. If they already have an active Kinde session, Kinde sends the SAML assertion to the application without asking them to sign in, and the workflow does not run. Don’t expect a workflow run for every request the service provider sends to Kinde.

How often users sign in depends on the application’s session settings:

  • When Force re-authentication is on, users sign in every time they open the application, so the workflow runs every time.
  • When it is off, a signed-in user is only asked to sign in again once the application’s Session lifetime has passed since they last signed in. The workflow runs at that sign-in.

The clientId values in the event are the client ID of Kinde’s self-serve portal application, not an ID for the SAML application. Sign-ins to the self-serve portal itself use the same client ID, and nothing else in the event identifies the SAML application. Keep this in mind if your workflow branches on client ID.

Workflows can’t change the SAML assertion Kinde sends to the application. See SAML applications.

Sample event object

Link to this section

The main argument provided to your code is the Kinde workflow event object which has two keys request and context. This gives you access to the reason the workflow was triggered and additional relevant datapoints. Here’s an example:

{
"request": {
"ip": "***",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0",
"authUrlParams": {
"state": "b9ea1131f7796a10abe8eac1b48c715575a0ffd349fb9c602e13d824",
"orgCode": "org_12345667",
"clientId": "cad2d86b1ac645e1957889fcb1eff0f9",
"redirectUri": "http://localhost:3000"
}
},
"context": {
"auth": {
"connectionId": "conn_0194ee03c226d48c6858d5a412359ed2",
"isNewUserRecordCreated": true
},
"user": {
"id": "kp_6e54d9612e8748b39557c9975bdba033"
},
"domains": {
"kindeDomain": "https://newbus.localkinde.me"
},
"workflow": {
"trigger": "user:post_authentication"
},
"application": {
"clientId": "cad2d86b1ac645e1957889fcb1eff0f9"
}
}
}

Example workflows

Link to this section

See examples on GitHub: