FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    How can I pass info from a external identity provider to a JWT in FusionAuth

    Scheduled Pinned Locked Moved
    Q&A
    jwt identity provider customization
    0
    2
    3.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • danD
      dan
      last edited by dan

      I am using an external identity provider which sends back some information that I want to add to my JWT. How can I do this?

      --
      FusionAuth - Auth for devs, built by devs.
      https://fusionauth.io

      1 Reply Last reply Reply Quote 0
      • danD
        dan
        last edited by

        The way to do this is to use the user.data or registration.data objects as a transfer mechanism.

        If you are using OIDC (SAML is much the same, but I'll use OIDC as an example), you can create a OIDC Reconcile Lambda. It might look like this:

        // Using the JWT returned from UserInfo, reconcile the User and User Registration.
        function reconcile(user, registration, jwt) {
          user.data.favoriteColor = jwt.favoriteColor;
        }
        

        So the jwt in this case is that returned from the OIDC identity provider. We store the data in user.data.

        Now we need to pull it off of the user.data object using a JWT populate lambda. That might look a little something like this:

        // Using the user and registration parameters add additional values to the jwt object.
        function populate(jwt, user, registration) {
          jwt.favoriteColor = user.data.favoriteColor;
        }
        

        favoriteColor is now available as a claim in the JWT produced by FusionAuth.

        Don't forget to assign your lambdas to the correct operations. The OIDC Identity provider needs to be configured with the reconcile lambda. The application's JWT tab is the right place to configure the use of the JWT populate lambda.

        More information on all the lambda options available here: https://fusionauth.io/docs/v1/tech/lambdas/

        --
        FusionAuth - Auth for devs, built by devs.
        https://fusionauth.io

        1 Reply Last reply Reply Quote 0
        • First post
          Last post