FusionAuth developer image
FusionAuth developer logo
  • Back to site
  • Expert Advice
  • Blog
  • Developers
  • Downloads
  • Account
  • Contact sales
Navigate to...
  • Welcome
  • Getting Started
    • Getting Started
    • 5-minute Setup Guide
      • Overview
      • Docker
      • Fast Path
      • Sandbox
    • Setup Wizard & First Login
    • Register a User and Login
    • Self-service Registration
    • Start and Stop FusionAuth
    • Core Concepts
      • Overview
      • Users
      • Roles
      • Groups
      • Registrations
      • Applications
      • Tenants
      • Identity Providers
      • Authentication/Authorization
      • Integration Points
    • Example Apps
      • Overview
      • Dart
      • Go
      • Java
      • JavaScript
      • .NET Core
      • PHP
      • Python
      • Ruby
    • Tutorials
  • Installation Guide
    • Overview
    • System Requirements
    • Server Layout
    • Cloud
    • Cluster
    • Docker
    • Fast Path
    • Kubernetes
      • Overview
      • Deployment Guide
      • Minikube Setup
      • Amazon EKS Setup
      • Google GKE Setup
      • Microsoft AKS Setup
    • Kickstart™
    • Homebrew
    • Marketplaces
    • Packages
    • Database
    • FusionAuth App
    • FusionAuth Search
    • Common Configuration
  • Migration Guide
    • Overview
    • General
    • Auth0
    • Keycloak
    • Amazon Cognito
    • Firebase
    • Microsoft Azure AD B2C
    • Tutorial
  • Admin Guide
    • Overview
    • Account Portal
    • Config Management
    • Editions and Features
    • Key Rotation
    • Licensing
    • Monitoring
    • Prometheus Setup
    • Proxy Setup
    • Reference
      • Overview
      • Configuration
      • CORS
      • Data Types
      • Hosted Login Pages Cookies
      • Known Limitations
      • Password Hashes
    • Releases
    • Roadmap
    • Search And FusionAuth
    • Securing
    • Switch Search Engines
    • Technical Support
    • Troubleshooting
    • Upgrading
    • WebAuthn
  • Login Methods
    • Identity Providers
      • Overview
      • Apple
      • Epic Games
      • External JWT
        • Overview
        • Example
      • Facebook
      • Google
      • HYPR
      • LinkedIn
      • Nintendo
      • OpenID Connect
        • Overview
        • Amazon Cognito
        • Azure AD
        • Discord
        • Github
      • Sony PlayStation Network
      • Steam
      • Twitch
      • Twitter
      • SAML v2
        • Overview
        • ADFS
        • Azure AD
      • SAML v2 IdP Initiated
        • Overview
        • Okta
      • Xbox
    • OIDC & OAuth 2.0
      • Overview
      • Endpoints
      • Tokens
      • OAuth Modes
    • Passwordless
      • Overview
      • Magic Links
      • WebAuthn & Passkeys
    • SAML v2 IdP
      • Overview
      • Google
      • Zendesk
  • Developer Guide
    • Overview
    • API Gateways
      • Overview
      • ngrok Cloud Edge
    • Client Libraries & SDKs
      • Overview
      • Dart
      • Go
      • Java
      • JavaScript
      • .NET Core
      • Node
      • OpenAPI
      • PHP
      • Python
      • React
      • Ruby
      • Typescript
    • Events & Webhooks
      • Overview
      • Writing a Webhook
      • Securing Webhooks
      • Events
        • Overview
        • Audit Log Create
        • Event Log Create
        • JWT Public Key Update
        • JWT Refresh
        • JWT Refresh Token Revoke
        • Kickstart Success
        • Group Create
        • Group Create Complete
        • Group Delete
        • Group Delete Complete
        • Group Update
        • Group Update Complete
        • Group Member Add
        • Group Member Add Complete
        • Group Member Remove
        • Group Member Remove Complete
        • Group Member Update
        • Group Member Update Complete
        • User Action
        • User Bulk Create
        • User Create
        • User Create Complete
        • User Deactivate
        • User Delete
        • User Delete Complete
        • User Email Update
        • User Email Verified
        • User IdP Link
        • User IdP Unlink
        • User Login Failed
        • User Login Id Dup. Create
        • User Login Id Dup. Update
        • User Login New Device
        • User Login Success
        • User Login Suspicious
        • User Password Breach
        • User Password Reset Send
        • User Password Reset Start
        • User Password Reset Success
        • User Password Update
        • User Reactivate
        • User Reg. Create
        • User Reg. Create Complete
        • User Reg. Delete
        • User Reg. Delete Complete
        • User Registration Update
        • User Reg. Update Complete
        • User Reg. Verified
        • User 2FA Method Add
        • User 2FA Method Remove
        • User Update
        • User Update Complete
    • Guides
      • Overview
      • Authentication Tokens
      • Exposing A Local Instance
      • JSON Web Tokens
      • Key Master
      • Localization and Internationalization
      • Multi-Factor Authentication
      • Multi-Tenant
      • Passwordless
      • Registration-based Email Verification
      • Searching With Elasticsearch
      • Securing Your APIs
      • Silent Mode
      • Single Sign-on
      • Two Factor (pre 1.26)
    • Integrations
      • Overview
      • CleanSpeak
      • Kafka
      • Twilio
    • Plugins
      • Overview
      • Writing a Plugin
      • Custom Password Hashing
    • User Control & Gating
      • Overview
      • Gate Unverified Users
      • Gate Unverified Registrations
      • User Account Lockout
  • Customization
    • Email & Templates
      • Overview
      • Configure Email
      • Email Templates
      • Email Variables
      • Message Templates
    • Lambdas
      • Overview
      • Apple Reconcile
      • Client Cred. JWT Populate
      • Epic Games Reconcile
      • External JWT Reconcile
      • Facebook Reconcile
      • Google Reconcile
      • HYPR Reconcile
      • JWT Populate
      • LDAP Connector Reconcile
      • LinkedIn Reconcile
      • Nintendo Reconcile
      • OpenID Connect Reconcile
      • SAML v2 Populate
      • SAML v2 Reconcile
      • SCIM Group Req. Converter
      • SCIM Group Resp. Convtr.
      • SCIM User Req. Converter
      • SCIM User Resp. Converter
      • Sony PSN Reconcile
      • Steam Reconcile
      • Twitch Reconcile
      • Twitter Reconcile
      • Xbox Reconcile
    • Messengers
      • Overview
      • Generic Messenger
      • Twilio Messenger
    • Themes
      • Overview
      • Examples
      • Helpers
      • Localization
      • Template Variables
  • Premium Features
    • Overview
    • Advanced Registration Forms
    • Advanced Threat Detection
    • Application Specific Themes
    • Breached Password Detection
    • Connectors
      • Overview
      • Generic Connector
      • LDAP Connector
      • FusionAuth Connector
    • Entity Management
    • SCIM
      • Overview
      • Azure AD Client
      • Okta Client
      • SCIM-SDK
    • Self Service Account Mgmt
      • Overview
      • Updating User Data & Password
      • Add Two-Factor Authenticator
      • Add Two-Factor Email
      • Add Two-Factor SMS
      • Add WebAuthn Passkey
      • Customizing
      • Troubleshooting
    • WebAuthn
  • APIs
    • Overview
    • Authentication
    • Errors
    • API Explorer
    • Actioning Users
    • API Keys
    • Applications
    • Audit Logs
    • Connectors
      • Overview
      • Generic
      • LDAP
    • Consents
    • Emails
    • Entity Management
      • Overview
      • Entities
      • Entity Types
      • Grants
    • Event Logs
    • Families
    • Forms
    • Form Fields
    • Groups
    • Identity Providers
      • Overview
      • Links
      • Apple
      • External JWT
      • Epic Games
      • Facebook
      • Google
      • HYPR
      • LinkedIn
      • Nintendo
      • OpenID Connect
      • SAML v2
      • SAML v2 IdP Initiated
      • Sony PlayStation Network
      • Steam
      • Twitch
      • Twitter
      • Xbox
    • Integrations
    • IP Access Control Lists
    • JWT
    • Keys
    • Lambdas
    • Login
    • Message Templates
    • Messengers
      • Overview
      • Generic
      • Twilio
    • Multi-Factor/Two Factor
    • Passwordless
    • Reactor
    • Registrations
    • Reports
    • SCIM
      • Overview
      • SCIM User
      • SCIM Group
      • SCIM EnterpriseUser
      • SCIM Service Provider Config.
    • System
    • Tenants
    • Themes
    • Users
    • User Actions
    • User Action Reasons
    • User Comments
    • WebAuthn
    • Webhooks
  • Release Notes

    Client Credentials JWT Populate lambda

    Client Credentials JWT Populate lambda

    If you would like to augment the claims provided in the JWT before it has been signed you can specify a lambda in the JWT configuration. This lambda will be invoked prior to the token being signed and issued as a result of the client credentials grant, on behalf of an Entity.

    When you create a new lambda using the FusionAuth UI we will provide you an empty function for you to implement. If you are using the API to create the lambda you will need to ensure your function has the following signature:

    
    function populate(jwt, recipientEntity, targetEntities, permissions) {
      // Lambda code goes here
    }

    This lambda must contain a function named populate that takes four parameters. The parameters that the lambda is passed are:

    • jwt - the claims object to be signed and return as the JWT payload

    • recipientEntity - the Recipient Entity. See an example below.

    • targetEntities - the Target Entities. See an example below.

    • permissions - the permissions assigned to the Entity. Example below.

    The recipientEntity and targetEntities objects are well documented here in the Permissions & Entity Types APIs and Entities API documentation. The JWT object is a JavaScript object containing the JWT payload. See here for more.

    You may add or modify anything in the jwt object. However, you may not modify the header keys or values of the JWT. FusionAuth also protects certain reserved claims. The following claims are considered reserved and modifications or removal will not be reflected in the final JWT payload:

    • aud

    • exp

    • iat

    • permissions

    • sub

    • tid

    The tid claim was added in version 1.36.0.

    Assigning the Lambda

    Once a lambda is created, you must assign it. To do so via the administrative user interface, navigate to Tenants → Your Tenant → OAuth and update the Client credentials populate lambda setting.

    Example Entities and Permissions Objects

    For these example objects (available in the lambda) there are three entities created (reminder, todo, and email) with an api entity type with read and write user defined permission values.

    Example JSON for recipientEntity object.
    
    {
      "clientId":          "9d570ab2-8705-483b-8cbd-9dd74935fce1",
      "clientSecret":      "LUtIbHgOiCwOjVGDwTcgNaYELJAJJyj-qzhT5XQzhvE",
      "data":              {},
      "id":                "9d570ab2-8705-483b-8cbd-9dd74935fce1",
      "insertInstant":     1625005371790,
      "lastUpdateInstant": 1625005371790,
      "name":              "Reminder API",
      "tenantId":          "30663132-6464-6665-3032-326466613934",
      "type":              {
        "data":              {},
        "id":                "0bd2dcc9-6389-494e-b0cd-743de05d67a5",
        "insertInstant":     1625002067313,
        "jwtConfiguration":  {
          "enabled":             false,
          "timeToLiveInSeconds": 60
        },
        "lastUpdateInstant": 1625002067313,
        "name":              "API",
        "permissions":       [
          {
            "data":              {},
            "description":       "read something",
            "id":                "640e7e1c-5f39-458c-ba0f-15c1e1c0eac7",
            "insertInstant":     1625007399127,
            "isDefault":         false,
            "lastUpdateInstant": 1625007399127,
            "name":              "read"
          },
          {
            "data":              {},
            "description":       "write something",
            "id":                "41ea8074-43b1-4b08-845c-418dacdc0a44",
            "insertInstant":     1625007410986,
            "isDefault":         false,
            "lastUpdateInstant": 1625007410986,
            "name":              "write"
          }
        ]
      }
    }
    Example JSON for targetEntities object.
    
    {
      "0b56a9ff-5e5d-4969-9cc2-3f1f49e5c64d": {
        "clientId":          "0b56a9ff-5e5d-4969-9cc2-3f1f49e5c64d",
        "clientSecret":      "dSD5mxPXEF-SJL6LPxOAFOwgU6vwitzixlMafHiJWIM",
        "data":              {},
        "id":                "0b56a9ff-5e5d-4969-9cc2-3f1f49e5c64d",
        "insertInstant":     1625005404087,
        "lastUpdateInstant": 1625005404087,
        "name":              "Email API",
        "tenantId":          "30663132-6464-6665-3032-326466613934",
        "type":              {
          "data":              {},
          "id":                "0bd2dcc9-6389-494e-b0cd-743de05d67a5",
          "insertInstant":     1625002067313,
          "jwtConfiguration":  {
            "enabled":             false,
            "timeToLiveInSeconds": 60
          },
          "lastUpdateInstant": 1625002067313,
          "name":              "API",
          "permissions":       [
            {
              "data":              {},
              "description":       "read something",
              "id":                "640e7e1c-5f39-458c-ba0f-15c1e1c0eac7",
              "insertInstant":     1625007399127,
              "isDefault":         false,
              "lastUpdateInstant": 1625007399127,
              "name":              "read"
            },
            {
              "data":              {},
              "description":       "write something",
              "id":                "41ea8074-43b1-4b08-845c-418dacdc0a44",
              "insertInstant":     1625007410986,
              "isDefault":         false,
              "lastUpdateInstant": 1625007410986,
              "name":              "write"
            }
          ]
        }
      },
      "b22a5012-3464-4490-bc1b-603d6d9d619b": {
        "clientId":          "b22a5012-3464-4490-bc1b-603d6d9d619b",
        "clientSecret":      "ICCUTaPG0-6rfcW65zFFNPe0N7MAF6CkFOu5sWan4Xo",
        "data":              {},
        "id":                "b22a5012-3464-4490-bc1b-603d6d9d619b",
        "insertInstant":     1625002153314,
        "lastUpdateInstant": 1625002153314,
        "name":              "Todo API",
        "tenantId":          "30663132-6464-6665-3032-326466613934",
        "type":              {
          "data":              {},
          "id":                "0bd2dcc9-6389-494e-b0cd-743de05d67a5",
          "insertInstant":     1625002067313,
          "jwtConfiguration":  {
            "enabled":             false,
            "timeToLiveInSeconds": 60
          },
          "lastUpdateInstant": 1625002067313,
          "name":              "API",
          "permissions":       [
            {
              "data":              {},
              "description":       "read something",
              "id":                "640e7e1c-5f39-458c-ba0f-15c1e1c0eac7",
              "insertInstant":     1625007399127,
              "isDefault":         false,
              "lastUpdateInstant": 1625007399127,
              "name":              "read"
            },
            {
              "data":              {},
              "description":       "write something",
              "id":                "41ea8074-43b1-4b08-845c-418dacdc0a44",
              "insertInstant":     1625007410986,
              "isDefault":         false,
              "lastUpdateInstant": 1625007410986,
              "name":              "write"
            }
          ]
        }
      }
    }
    Example JSON for permissions object.
    
    {
      "0b56a9ff-5e5d-4969-9cc2-3f1f49e5c64d": [
        "write"
      ],
      "b22a5012-3464-4490-bc1b-603d6d9d619b": [
        "read"
      ]
    }

    Related

    Related information about Client Credentials Grant.

    Feedback

    How helpful was this page?

    See a problem?

    File an issue in our docs repo

    Have a question or comment to share?

    Visit the FusionAuth community forum.

    © 2023 FusionAuth
    Subscribe for developer updates