Skip to main content
The API object for the post-login Actions trigger includes:

api.access

Modify the access of the user that is logging in, such as rejecting the login attempt.

api.access.deny(reason)

Mark the current login attempt as denied. This will prevent the end-user from completing the login flow. This will NOT cancel other user-related side-effects (such as metadata changes) requested by this Action. The login flow will immediately stop following the completion of this action and no further Actions will be executed. Parameters

api.accessToken

Request changes to the access token being issued.

api.accessToken.setCustomClaim(key, value)

Set a custom claim on the Access Token that will be issued upon completion of the login flow. Parameters

api.accessToken.addScope(scope)

Add a scope on the Access Token that will be issued upon completion of the login flow. Parameters

api.accessToken.removeScope(scope)

Remove a scope on the Access Token that will be issued upon completion of the login flow. Parameters

api.authentication

Request changes to the authentication state of the current user’s session.

api.authentication.challengeWith(factor, options)

Request a challenge for multifactor authentication using the supplied factor and optional additional factors. When a multifactor challenge is requested, subsequent Actions will not be run until that challenge has been fulfilled by the user. A user will have satisfied the challenge in any of the following situations:
  1. They successfully complete the challenge for the default factor.
  2. They successfully complete the challenge for any of the optional factors described in additionalFactors.
If any of the factors requested has already been challenged successfully in the current transaction, it will be ignored. If a factor is requested is not enabled on the tenant, it will be ignored. If a factor is requested that the user has not enrolled, it will be ignored. If none of the requested factors is enabled or enrolled, the authentication transaction will fail (i.e. login will not complete).
This method will result in a factor challenge screen being shown if the user has not already satisfied the requirements of the challenge. If additionalFactors are supplied, the user will have the option to select another factor if they choose to.
Challenge with a specific factor
Challenge with additional factors
Challenge with push notification and disable OTP fallback
Parameters

api.authentication.challengeWithAny(factors)

Request a challenge for multifactor authentication using any of the supplied factors (showing a factor selection screen first). When a multifactor challenge is requested, subsequent Actions will not be run until that challenge has been fulfilled by the user. A user will have satisfied the challenge in any of the following situations:
  1. They successfully complete the challenge for any of the factors.
If any of the factors requested has already been challenged successfully in the current transaction, it will be ignored. If a factor is requested is not enabled on the tenant, it will be ignored. If a factor is requested that the user has not enrolled, it will be ignored. If none of the requested factors is enabled or enrolled, the authentication transaction will fail (i.e. login will not complete).
This method will result in the factor selector screen being shown if the user has not already satisfied the requirements of the challenge. If there is a preferred factor, the api.authentication.challengeWith() method is preferred. The factor selector screen will not be shown if only one factor is passed in or is valid.
Parameters

api.authentication.enrollWith(factor, options)

Request an enrollment for multifactor authentication using the supplied factor and optional additional factors. When a multifactor enrollment is requested, subsequent Actions will not be run until that enrollment has been fulfilled by the user. If any of the factors requested has already been enrolled or challenged successfully in the current transaction, it will be ignored. If a factor that is not enabled in the tenant is requested, it will be ignored. If a factor that the user has already enrolled is requested, it will be ignored. If none of the requested factors is enabled and not enrolled, the authentication transaction will fail (i.e. login will not complete).
Enroll with additional factors
Parameters

api.authentication.enrollWithAny(factors)

Request an enrollment for multifactor authentication using any of the supplied factors (showing a factor selection screen first). When a multifactor enrollment is requested, subsequent Actions will not be run until that enrollment has been fulfilled by the user. If any of the factors requested has already been enrolled successfully in the current transaction, it will be ignored. If a factor that is not enabled in the tenant is requested, it will be ignored. If a factor that the user has already enrolled is requested, it will be ignored. If none of the requested factors is enabled and not enrolled, the authentication transaction will fail (i.e. login will not complete).
If there is a preferred factor, the api.authentication.enrollWith() method is preferred. The factor selector screen will not be shown if only one factor is passed in or is valid.
Parameters

api.authentication.recordMethod(provider_url)

Indicate that a custom authentication method has been completed in the current session. This method will then be available in the event.authentication.methods array in subsequent logins. IMPORTANT: This API is only available from within the onContinuePostLogin function for PostLogin Actions. In other words, this may be used to record the completion of a custom authentication method after redirecting the user via api.redirect.sendUserTo(). Parameters

api.authentication.setPrimaryUser(primary_user_id)

Change the primary user for the login transaction. In scenarios that require linking users, the user identity used to initiate the login may no longer exist as a discrete user. That identity may now be a secondary identity of an existing user. In such situations, the setPrimaryUser() function can be used to indicate that the subject of the login should be changed. IMPORTANT: Insecurely linking accounts can allow malicious actors to access legitimate user accounts. IMPORTANT: The identity used to authenticate the login must be among the secondary identities of the user referenced by primary_user_id. The login will fail and tokens will not be issued otherwise. Parameters

api.idToken

Request changes to the ID token being issued.

api.idToken.setCustomClaim(key, value)

Set a custom claim on the ID Token that will be issued upon completion of the login flow. Parameters

api.multifactor

Set or remove the requirement for multifactor authentication on the login attempt.

api.multifactor.enable(provider, options)

Enable multifactor authentication for this login flow. When enabled, users must complete the configured multifactor challenge. The actual multifactor challenge will be deferred to the end of the login flow. Parameters

api.redirect

Configure and initiate external redirects.

api.redirect.encodeToken(options)

Create a session token suitable for using as a query string parameter redirect target (via sendUserTo) that contains data whose authenticity must be provable by the target endpoint. The target endpoint can verify the authenticity and integrity of the data by checking the JWT’s signature using a shared secret. The shared secret should be stored as a secret of the Action and will be readable at event.secrets['<secret_name>']. Parameters

api.redirect.sendUserTo(url, options)

Cause the login pipeline to trigger a browser redirect to the target url immediately after this action completes. The createUrl helper method is provided to simplify encoding data as a query parameter in the target url such that the data’s authenticity and integrity can be verified by the target endpoint. Parameters

api.redirect.canRedirect()

Indicates if the current transaction is eligibile for a user redirect. Certain protocols such as oauth2-resource-owner, oauth2-refresh-token do not support redirecting the user. A request with prompt=none is also not eligible for a redirect.

api.redirect.validateToken(options)

Retrieve the data encoded in a JWT token passed to the /continue endpoint while verifying the authenticity and integrity of that data. Parameters

api.user

Make changes to the metadata of the user that is logging in.

api.user.setAppMetadata(key, value)

Set application-specific metadata for the user that is logging in. Note: This method should not be used in callbacks. Invoking this method won’t update the metadata immediately. You can call this several times throughout multiple actions of the same flow and the engine will aggregate the changes and update the metadata at once before the flow is completed. This function works only with metadata that are in the object format. Parameters

api.user.setUserMetadata(key, value)

Set general metadata for the user that is logging in. Note: This method should not be used in callbacks. Invoking this method won’t update the metadata immediately. You can call this several times throughout multiple actions of the same flow and the engine will aggregate the changes and update the metadata at once before the flow is completed. This function works only with metadata that are in the object format. Parameters

api.cache

Make changes to the cache.

api.cache.delete(key)

Delete a record describing a cached value at the supplied key if it exists. Parameters

api.cache.get(key)

Retrieve a record describing a cached value at the supplied key, if it exists. If a record is found, the cached value can be found at the value property of the returned object. Parameters

api.cache.set(key, value, options)

Store or update a string value in the cache at the specified key. Values stored in this cache are scoped to the Trigger in which they are set. They are subject to the Actions Cache Limits. Values stored in this way will have lifetimes of up to the specified ttl or expires_at values. If no lifetime is specified, a default of lifetime of 15 minutes will be used. Lifetimes may not exceed the maximum duration listed at Actions Cache Limits. Important: This cache is designed for short-lived, ephemeral data. Items may not be available in later transactions even if they are within their supplied their lifetime. Parameters

api.samlResponse

Configure custom SAML configurations and attributes.

api.samlResponse.setAttribute(attribute, value)

Set attributes on the SAML assertion being issued to the authenticated user. Parameters

api.samlResponse.setAudience(audience)

Audience of the SAML assertion. Default is issuer on SAMLRequest. Parameters

api.samlResponse.setRecipient(recipient)

Recipient of the SAML assertion (SubjectConfirmationData). Default is AssertionConsumerUrl on SAMLRequest or callback URL if no SAMLRequest was sent. Parameters

api.samlResponse.setCreateUpnClaim(createUpnClaim)

Whether or not a UPN claim should be created. Default is true. Parameters

api.samlResponse.setPassthroughClaimsWithNoMapping(passthroughClaimsWithNoMapping)

If true (default), for each claim that is not mapped to the common profile, Auth0 passes through those in the output assertion. If false, those claims won’t be mapped. Parameters

api.samlResponse.setMapUnknownClaimsAsIs(mapUnknownClaimsAsIs)

If passthroughClaimsWithNoMapping is true and this is false (default), for each claim not mapped to the common profile Auth0 adds a prefix http://schema.auth0.com. If true it will pass through the claim as-is. Parameters

api.samlResponse.setMapIdentities(mapIdentities)

If true (default), it adds more information in the token such as the provider (Google, ADFS, AD, etc.) and the access token, if available. Parameters

api.samlResponse.setSignatureAlgorithm(signatureAlgorithm)

Signature algorithm to sign the SAML assertion or response. Default is rsa-sha256. Parameters

api.samlResponse.setSignatureAlgorithm(signatureAlgorithm)

Parameters

api.samlResponse.setDigestAlgorithm(digestAlgorithm)

Digest algorithm to calculate digest of the SAML assertion or response. Default is sha256. Parameters

api.samlResponse.setDigestAlgorithm(digestAlgorithm)

Parameters

api.samlResponse.setDestination(destination)

Destination of the SAML response. If not specified, it will be AssertionConsumerUrl of SAMLRequest or callback URL if there was no SAMLRequest. Parameters

api.samlResponse.setLifetimeInSeconds(lifetimeInSeconds)

Expiration of the token. Default is 3600 seconds (1 hour). Parameters

api.samlResponse.setSignResponse(signResponse)

Whether or not the SAML response should be signed. By default the SAML assertion will be signed, but not the SAML response. If true, SAML Response will be signed instead of SAML assertion. Default to false. Parameters

api.samlResponse.setNameIdentifierFormat(nameIdentifierFormat)

Default is urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified. Parameters

api.samlResponse.setNameIdentifierProbes(nameIdentifierProbes)

Auth0 will try each of the attributes of this array in order. If one of them has a value, it will use that for the Subject/NameID. The order is: Parameters

api.samlResponse.setAuthnContextClassRef(authnContextClassRef)

Default is urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified. Parameters

api.samlResponse.setSigningCert(signingCert)

Optionally indicates the public key certificate used to validate SAML requests. If set, SAML requests will be required to be signed. A sample value would be “-----BEGIN CERTIFICATE-----\nMIIC8jCCAdqgAwIBAgIJObB6jmhG0QIEMA0GCSqGSIb3DQEBBQUAMCAxHjAcBgNV\n[..all the other lines..]-----END CERTIFICATE-----\n”. Parameters

api.samlResponse.setIncludeAttributeNameFormat(includeAttributeNameFormat)

When set to true, we infer the NameFormat based on the attribute name. NameFormat values are urn:oasis:names:tc:SAML:2.0:attrname-format:uri, urn:oasis:names:tc:SAML:2.0:attrname-format:basic and urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified. If set to false, the attribute NameFormat is not set in the assertion. Default is true. Parameters

api.samlResponse.setTypedAttributes(typedAttributes)

When set to true, we infer the xs:type of the element. Types are xs:string, xs:boolean, xs:double and xs:anyType. When set to false all xs:type are xs:anyType. Default is true. Parameters

api.samlResponse.setEncryptionCert(encryptionCert)

Optionally specify a certificate used to encrypt the SAML assertion. The certificate should be obtained from the service provider. Both the certificate and public key must be specified. A sample value would be “-----BEGIN CERTIFICATE-----\nMIIC8jCCAdqgAwIBAgIJObB6jmhG0QIEMA0GCSqGSIb3DQEBBQUAMCAxHjAcBgNV\n[..all the other lines..]-----END CERTIFICATE-----\n”. Parameters

api.samlResponse.setEncryptionPublicKey(encryptionPublicKey)

Optionally specify a public key used to encrypt the SAML assertion. The public key should be obtained from the service provider. Both the public key and certificate must be specified. A sample value would be “-----BEGIN PUBLIC KEY-----\nnMIIC8jCCAdqgAwIBAgIJObB6jmhG0QIEMA0GCSqGSIb3DQEBBQUAMCAxHjAcBgNV\n[..all the other lines..]-----END PUBLIC KEY-----\n”. Parameters

api.samlResponse.setCert(cert)

By default, Auth0 will use the private/public key pair assigned to your tenant to sign SAML responses or assertions. For very specific scenarios, you might wish to provide your own certificate and private key. Both the certificate and private key must be specified. A sample value would be “-----BEGIN CERTIFICATE-----\nMIIC8jCCAdqgAwIBAgIJObB6jmhG0QIEMA0GCSqGSIb3DQEBBQUAMCAxHjAcBgNV\n[..all the other lines..]-----END CERTIFICATE-----\n”. Parameters

api.samlResponse.setKey(key)

By default, Auth0 will use the private/public key pair assigned to your tenant to sign SAML responses or assertions. For very specific scenarios, you might wish to provide your own certificate and private key. Since this private key is sensitive, we recommend using the Add Secret functionality of Actions. See here for more details: https://auth0.com/docs/customize/actions/write-your-first-action#add-a-secret Both the certificate and private key must be specified. A sample value would be “-----BEGIN PRIVATE KEY-----\nnMIIC8jCCAdqgAwIBAgIJObB6jmhG0QIEMA0GCSqGSIb3DQEBBQUAMCAxHjAcBgNV\n[..all the other lines..]-----END PRIVATE KEY-----\n”. Parameters

api.samlResponse.setRelayState(relayState)

Optionally specify a RelayState used to return to service provider Parameters

api.samlResponse.setIssuer(issuer)

Optionally specify the issuer of the SAML assertion. Default is urn:auth0:TENANT Parameters

api.samlResponse.setEncryptionAlgorithm(encryptionAlgorithm)

Set encryption algorithm for SAML assertion. Default is aes256-cbc.
Set the encryption algorithm to aes256-gcm (recommended)
Parameters

api.samlResponse.setEncryptionAlgorithm(encryptionAlgorithm)

Set encryption algorithm to aes256-cbc (not recommended)
Parameters

api.validation

Prevent user from logging in by throwing a validation error.

api.validation.error(errorCode, errorMessage)

Throw an error when there is a validation error. Parameters

api.rules

Identify if a rule has been executed in the current transaction.

api.rules.wasExecuted(ruleId)

Check whether a Rule with a specific ID has been executed in the current transaction. Parameters

api.prompt

Renders a custom prompt.

api.prompt.render(promptId, promptOptions)

Renders a custom prompt. Parameters

api.refreshToken

Request changes to the current user’s refresh token.

api.refreshToken.revoke(reason)

[Enterprise Customers] Revoke the current user refresh token and mark the current refresh token exchange attempt as denied. This will prevent the end-user from completing the refresh token exchange flow and revoke the currently used refresh token. The refresh token exchange flow will immediately stop following the completion of this action and no further Actions will be executed. This method can be used only during Refresh Token Exchange flow, when event.transaction.protocol === "oauth2-refresh-token". Parameters

api.refreshToken.setExpiresAt(absolute)

[Enterprise Customers] Sets a new absolute expiration time for the current refresh token. The expiration cannot be set higher than the maximum refresh token lifetime set in the settings. When called multiple times, the earliest expiration time will be used. Parameters

api.refreshToken.setIdleExpiresAt(inactivity)

[Enterprise Customers] Sets a new idle expiration time for the current refresh token. The expiration cannot be set higher than the maximum absolute refresh token lifetime set in the settings. When called multiple times, the earliest expiration time will be used. Parameters

api.refreshToken.setMetadata(key, value)

Sets a key value pair in the metadata object of the current refresh token. Parameters

api.refreshToken.deleteMetadata(key)

Deletes a key in the metadata object of the current refresh token. Parameters

api.refreshToken.evictMetadata()

Deletes all keys from the metadata object of the current refresh token.

api.session

Request changes to the current user’s session.

api.session.revoke(reason, options)

[Enterprise Customers] Revoke the current user session and mark the current login attempt as denied. This will prevent the end-user from completing the login flow and revoke their session. The login flow will immediately stop following the completion of this action and no further Actions will be executed.
Revoke the session while preserving refresh tokens
Parameters

api.session.setExpiresAt(absolute)

[Enterprise Customers] Sets a new absolute expiration time for the current session. The expiration cannot be set higher than the maximum session lifetime set in the tenant settings. When called multiple times, the earliest expiration time will be used. Parameters

api.session.setIdleExpiresAt(inactivity)

[Enterprise Customers] Sets a new idle expiration time for the current session. The expiration cannot be set higher than the maximum absolute session lifetime set in the tenant settings. When called multiple times, the earliest expiration time will be used. Parameters

api.session.setCookieMode(mode)

[Enterprise Customers] [Early Access] Sets the cookie mode for the current session, allowing it to be either ‘persistent’ or ‘non-persistent’ (ephemeral). This determines how the session cookie is handled in the browser:
  • ‘persistent’: The cookie will be stored until it expires or is deleted by the user.
  • ‘non-persistent’ (ephemeral): The cookie will be deleted when the browser is closed.
If multiple setCookieMode invocations are made, only the last one will take effect. In case ‘non-persistent’ is set, the cookie will be deleted when the browser is closed, however, the session itself will remain valid until its absolute or idle expiration time is reached or the session is revoked through our available APIs. For more information on cookie modes, please refer to our documentation. Parameters

api.session.setMetadata(key, value)

[Enterprise Customers] [Early Access] Sets a key value pair in the metadata object of the current session. Parameters

api.session.deleteMetadata(key)

[Enterprise Customers] [Early Access] Deletes a key in the metadata object of the current session. Parameters

api.session.evictMetadata()

[Enterprise Customers] [Early Access] Deletes all keys from the metadata object of the current session.

api.transaction

Make changes to the transaction.

api.transaction.setMetadata(key, value)

Store or update the value in the transaction metadata for a specified key. Metadata modified using this method is updated in real-time in the event.transaction.metadata object. Parameters

api.groups

Get information about user groups membership.

api.groups.getUserGroups(params)

Get the paginated list of the groups the user belongs to. Parameters

api.groups.hasGroupMembership(groups)

Checks if the user is a member of any of the specified groups and provides details about the matching groups if the user is a member. Parameters