K
Kinde8mo ago
9M6

kindeClient.getUserOrganizations() its returning Compact JWS must be a string or Uint8Array

I am getting an error when fetching: kindeClient.getUserOrganizations() its returning Compact JWS must be a string or Uint8Array, but when I fetch other functions works correctly any idea why this might happen? My setup is Nuxt+NitroJS (nodejs) I have setup: 1. M2M to fetch tokens to make endpoint api calls 2. Copy/Pasted the nuxt-kinde server/ code to my nitro app Tried asking KindeAI, but to no avail.
18 Replies
9M6
9M6OP8mo ago
stack": [
"JWSInvalid: Compact JWS must be a string or Uint8Array",
"at compactVerify (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/[email protected]/node_modules/jose/dist/node/esm/jws/compact/verify.js:9:15)",
"at jwtVerify (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/[email protected]/node_modules/jose/dist/node/esm/jwt/verify.js:5:28)",
"at file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:142:45",
"at step (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:32:23)",
"at Object.next (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:13:53)",
"at fulfilled (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:4:58)"
]
stack": [
"JWSInvalid: Compact JWS must be a string or Uint8Array",
"at compactVerify (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/[email protected]/node_modules/jose/dist/node/esm/jws/compact/verify.js:9:15)",
"at jwtVerify (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/[email protected]/node_modules/jose/dist/node/esm/jwt/verify.js:5:28)",
"at file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:142:45",
"at step (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:32:23)",
"at Object.next (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:13:53)",
"at fulfilled (file:///Users/mypc/Laboratory/project/org.project.api/node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/utilities/token-utils.js:4:58)"
]
Hello @Oli - Kinde @viv (kinde) sorry to ping you on this, but this issue is very difficult to debug. when accessing some functions the call are successful, in some other functions like getUser the functions throws this error. getUserProfile works getUser throws the above error getToken works getOrganization works getUserOrganizations doesnt work Why is this the SDK so inconsistent? CC: @Daniel_Kinde
Oli - Kinde
Oli - Kinde8mo ago
Hey @9M6, Whats SDK are you using?
9M6
9M6OP8mo ago
Hello @Oli - Kinde I'm using the node typescript sdk is this a known issue? I've also copied code from the nuxt-kinde server/ library to my nitro project
Oli - Kinde
Oli - Kinde8mo ago
Hi @9M6, No this is not a known issue. I will get a member of my team to look into this Have you tried the Nuxt SDK?
9M6
9M6OP8mo ago
I use that on the nuxt app, but I'm separating the backend from nuxt so I'm using both nuxt + backend with nitro and migrated some code into nitro it should work the exact same same since the middleware and the util functions are the same
Oli - Kinde
Oli - Kinde8mo ago
Okay I will reach out to a team member of mine to look into this issue.
9M6
9M6OP8mo ago
I need this since I am also adding the kinde management api Thank you!
Daniel_Kinde
Daniel_Kinde8mo ago
Hi @9M6, just so I get on the right page, you're not using the Nuxt Module and building your own implementation with the TS SDK? There is no need to build your own management API layer, we have a packge which fully works with Nuxt already for this: https://github.com/kinde-oss/management-api-js
GitHub
GitHub - kinde-oss/management-api-js: javascript package for intera...
javascript package for interacting with the Kinde Management API - kinde-oss/management-api-js
9M6
9M6OP8mo ago
Hey @Daniel_Kinde First, I am already using nuxt-kinde on my nuxt app, but also I am building an API backend which I am using part of nuxt-kinde package, specifically the files in the server/ directory in there. I've integrated them into a separate nitro application, that will handle: 1. Authentication 2. Management API In there I've setup the Backend Application and a Machine 2 Machine Application, the auth layer is handled by the Backend application, while I get a oauth/token form M2M application, which then I will make requests on the backend for Management API. Also I am already using that API, I think it comes pre-bunddled with Kinde TypeScript SDK
Daniel_Kinde
Daniel_Kinde8mo ago
while I get a oauth/token form M2M application, which then I will make requests on the backend for Management API. All that is handled by the management-api-js linked above, the APIs in the TS SDK will likely be removed in future versions.
9M6
9M6OP8mo ago
Oh thats nice! but @Daniel_Kinde what about the other error? This JWT token issue its not related to the management API but the typescript SDK for the user api getUserProfile works getUser throws the above error getToken works getOrganization works getUserOrganizations doesnt work These are functions from typescript SDK when initialised through: createKindeServerClient I'm using GrantType.AUTHORIZATION_CODE The same implementation on nuxt-kinde @Daniel_Kinde switched to the new SDK, looks nice, but would be very nice if the init() function had a config parameter to pass down the env (automatically inferring the values from env variables is good too but the config will allow more customization) Also why there's is not any filtering capabilities for the endpoints. Example getOrganisations, would be nice to have a userId in there to filter based on that. Otherwise I would have to paginate through all orgs to filter it. @Daniel_Kinde it seems the only way to get additional details on the user is to use JWT tokens, and not any API. (Took me a while to understand this 😓 )
Daniel_Kinde
Daniel_Kinde8mo ago
You can access all the users properties using the Users.getUserPropertyValues method Is there something specifc you feel like you're missing?
9M6
9M6OP8mo ago
@Daniel_Kinde its returning only these props, but no organisation:
{
"code": "OK",
"message": "Success",
"properties": [
{
"id": "prop_018cc8f82e76373302a51e3f3d26832a",
"key": "kp_usr_city",
"name": "City",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e765da58f806a4f2aa9c4b2",
"key": "kp_usr_industry",
"name": "Industry",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76634b92b47af3f8a49666",
"key": "kp_usr_job_title",
"name": "Job title",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76039994fdd4152dc5263f",
"key": "kp_usr_middle_name",
"name": "Middle name",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76b6353574040fcf18a890",
"key": "kp_usr_postcode",
"name": "Postcode",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76d09ff3612f6610741a5e",
"key": "kp_usr_salutation",
"name": "Salutation",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e762987ee83dda047e08c4d",
"key": "kp_usr_state_region",
"name": "State/Region",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76a55c295d1a4b98b6b423",
"key": "kp_usr_street_address",
"name": "Street Address",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e7659a947dd11558691ab94",
"key": "kp_usr_street_address_2",
"name": "Street Address line 2",
"value": null,
"description": null
}
]
}
{
"code": "OK",
"message": "Success",
"properties": [
{
"id": "prop_018cc8f82e76373302a51e3f3d26832a",
"key": "kp_usr_city",
"name": "City",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e765da58f806a4f2aa9c4b2",
"key": "kp_usr_industry",
"name": "Industry",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76634b92b47af3f8a49666",
"key": "kp_usr_job_title",
"name": "Job title",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76039994fdd4152dc5263f",
"key": "kp_usr_middle_name",
"name": "Middle name",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76b6353574040fcf18a890",
"key": "kp_usr_postcode",
"name": "Postcode",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76d09ff3612f6610741a5e",
"key": "kp_usr_salutation",
"name": "Salutation",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e762987ee83dda047e08c4d",
"key": "kp_usr_state_region",
"name": "State/Region",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e76a55c295d1a4b98b6b423",
"key": "kp_usr_street_address",
"name": "Street Address",
"value": null,
"description": null
},
{
"id": "prop_018cc8f82e7659a947dd11558691ab94",
"key": "kp_usr_street_address_2",
"name": "Street Address line 2",
"value": null,
"description": null
}
]
}
Seems getUserData did the trick @Daniel_Kinde is there any method in the libraries where I can check the JWT token against the jwksendpoint? I saw some utility functions in the typescript libary but not sure if they're exported or for public access?
Daniel_Kinde
Daniel_Kinde8mo ago
GitHub
GitHub - kinde-oss/jwt-validator
Contribute to kinde-oss/jwt-validator development by creating an account on GitHub.
9M6
9M6OP8mo ago
Hey @Daniel_Kinde how to set the config during runtime? I'm using cloudflare pages, and .env are only set during the execution. if I just replicated/modified on my nitro app, the index.js with the config.js file in kinde-management-api, will it work? Any way of setting the Auth Domain, Client Id, and Client Secret?
9M6
9M6OP8mo ago
@Daniel_Kinde sent a PR with the changes https://github.com/kinde-oss/management-api-js/pull/8
GitHub
add config object in init() by 9M6 · Pull Request #8 · kinde-oss/ma...
Explain your changes Add a config parameter to the function init() the reason being is that there're cases where there's need to overwrite default configuration. Ex: cloudflare pages only p...
9M6
9M6OP8mo ago
Hey @Daniel_Kinde managed to look into this? I tried and works on my side, I also deployed my app on couldflare using my repo in the package manager
Daniel_Kinde
Daniel_Kinde8mo ago
Its on my list to review today
Want results from more Discord servers?
Add your server