Custom JWT Authentication provider metadata

We are in the process of porting our CosyncJWT service from Realm Cloud to MongoDB Realm. We have gotten the JWT authentication working well. My question concerns the Metadata fields, which are optional. This is obviously a new feature to MongoDB Realm because it did not exist in the older Realm Cloud product. Unfortunately, the documentation link " Learn more about this and how to use an identity provider." does not go anywhere. Is this feature a way to specify additional field data that is packaged inside of the JWT authentication token when a user logs in? I could see this being used to store coupon codes for a social media app. I am just at loss for how specifically this is implemented.

@Richard_Krueger I believe you are referring to Custom User data which can be defined here:
https://docs.mongodb.com/realm/users/define-custom-user-data/index.html

The link that you provided should be going to this link in the docs which should help.

if your JWT authentication token is passing in coupon codes for a user that looks like this, I imagine the JWT data would look like this:

{
      "aud": "myapp-abcde",
      "exp": 1516239022,
      "sub": "24601",
      "user_data": {
        "name": "John Doe",
        "coupons": [
          "123",
          "456",
        ]
      }
    }

You would define your fields like this:

Path Field // Name
user_data.name // name
user_data.coupons // coupons

and your user object would have coupon data in the following form:

{
  "id": "59fdd02846244cdse5369ebf",
  "type": "normal",
  "data": {
    "name": "John Doe",
    "coupons": [
          "123",
          "456"
        ]
  },
  identities: [
    {
      "id": "24601",
      "provider_type": "custom-token",
      "data": {
        "name": "John Doe",
        "coupons": [
          "123",
          "456"
        ]
      },
    }
  ]
}

@Sumedha_Mehta1 Again thanks for the quick turnaround, this was the link I was looking for. Somehow the link in the MongoDB Realm portal under providers Custom JWT Authentication is broken. This Metadata Fields options is a great feature, which was not in your older Realm Cloud offering, for it allows the signing authority to pass additional data inside the JWT token.

We are aware of some of the in-product links not working at the moment and are actively working on fixing them - they should be up and running soon.

Hi @Sumedha_Mehta1

I have been trying to use this JWT metadata configuration to extract the ‘sub’ from the JWT token into a custom field but I’m unable to do so.
Is this function broken or only limited to values on the token inside ‘user_data’ ?

Also - I have been trying to figure out how to link the user record in the MongoDB Realm portal to custom_data. Ideally I’d like my custom server to create the record in the custom_data collection - but I cannot seem to find a way for my server to fetch these records.
Can we not set the id of the realm users to be the sub value from the JWT token?

Thanks

B

Hi, @Richard_Krueger I bumped on to CosyncJWT and I am trying to implement it. I have managed to connect to Mongo Realm. I created a user but I was not able to see the user-created in Realm.

Another question, how do I get API endpoint for CosyncJWT to connect to the client? Thanks

@jaseme you can check out the sample code in this GitHub project

We have samples that call the API both from Swift and React Native.

Richard