Not a Function Error While Calling api.accessToken.addScope Inside an Auth0 Action

Overview

When calling api.accessToken.addScope inside an Auth0 Action, a not a function error occurs. This happens because the function is only available in version 3 of the Post-Login trigger, and the Action is currently using version 2. Patching the Action's supported triggers to use version 3 resolves the issue. When this failure occurs, Auth0 generates the following error:

 

api.accessToken.addScope is not a function

 

Applies To

  • Auth0
  • Actions
  • Post-Login Trigger
  • api.accessToken.addScope

Cause

The api.accessToken.addScope function is only available in version 3 of the Post-Login trigger. This error occurs if the Action uses version 2.

Solution

How is the "api.accessToken.addScope is not a function" error resolved?

Patch the action's supported triggers to use v3 of post-login instead of v2, using the following payload:

{ 
  "supported_triggers": [
    {
      "id": "post-login",
      "version": "v3"
    }
  ]
}


Example with curl:

$ curl -L -X PATCH 'https://<auth0 domain>/api/v2/actions/actions/<action id>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <management API token>' \
-d '{"supported_triggers":[{"id":"post-login","version":"v3"}]}'


Once patched, re-deploy the action, and the function should be available as expected.

 

Related References

Recommended content

No recommended content found...