Authentication Triggers¶
On this page
Overview¶
Authentication triggers allow you to execute server-side logic whenever a user interacts with an authentication provider. You can use authentication triggers to implement advanced user management, including storing new user data in MongoDB, maintaining data integrity when a user is deleted, or calling a service with a user’s information when they log in.
Create an Authentication Trigger¶
- Stitch UI
- Import/Export
To create an authentication trigger in the Stitch UI:
- Click Triggers under MongoDB Cluster in the left-hand navigation.
- Select the Authentication Triggers tab.
- Click Add Authentication Trigger in the top right to open the trigger configuration page.
- Enter configuration values for the trigger and click Save at the bottom of the page.
To create an authentication trigger with stitch-cli:
Add an authentication trigger configuration file to the
triggers
subdirectory of a local application directory.Note
Stitch does not enforce specific filenames for trigger configuration files. However, once imported, Stitch will rename each configuration file to match the name of the trigger it defines, e.g.
mytrigger.json
.Import the application directory into your application.
Reference¶
Authentication Trigger Configuration¶
- Stitch UI
- Import/Export
Authentication triggers have the following configuration parameters:
Configuration files for authentication triggers have the following form:
Field | Description |
---|---|
Trigger Type type
|
Required. The type of the trigger. For authentication triggers,
this value should be set to AUTHENTICATION . |
Trigger Name name
|
Required. The name of the trigger. |
Linked Function function_name
|
Required. The name of the Stitch function that the trigger executes whenever it fires. The trigger passes the authentication event object that caused it to fire as the only argument to this function. |
Operation Type config.operation_type
|
Required. The authentication operation
type that causes the
trigger to fire. The operation type must be formatted as a
fully-capitalized string, e.g. "LOGIN" . |
Providers config.providers
|
Required. A list of one or more authentication provider types. The trigger will only listen for authentication events produced by these providers. The following values are valid:
|
Authentication Events¶
Authentication events represent user interactions with an authentication provider. Each event corresponds to a single user action with one of the following operation types:
Operation Type | Description |
---|---|
LOGIN |
Represents a single instance of a user logging in. |
CREATE |
Represents the creation of a new user. |
DELETE |
Represents the deletion of a user. |
Authentication event objects have the following form:
Field | Description |
---|---|
operationType |
The operation type of the authentication event. |
providers |
The authentication providers that emitted the event. Each authentication provider is represented by one of the following names:
Note Generally, only one authentication provider emits each event.
If a user that is linked to
multiple providers is deleted, the |
user |
The user object of the user that interacted with the authentication provider. |
time |
The time at which the event occurred. |