Welcome to the Kinde community

Updated 4 months ago

Invalid Credentials for kinde/management-api-js

I have added the management-api-js package to my project and I don't know why but I have that error:
Plain Text
 ⨯ node_modules/@kinde/management-api-js/dist/kinde-management-api-js.cjs (1:25093) @ xt
 ⨯ Internal error: ApiError: Invalid credentials.
    at xt (./node_modules/@kinde/management-api-js/dist/kinde-management-api-js.cjs:1849:18)
    at eval (./node_modules/@kinde/management-api-js/dist/kinde-management-api-js.cjs:1876:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
digest: "2794529496"
null

I do have setup my project as told as in the docs so I'm kinda lost
Attachments
image.png
image.png
A
I
2 comments
Is this the first time you are using the API or just the management API SDK?

It might be a good idea to just double check a few things:

Enable API Access

First, ensure you've enabled your application's access to the Kinde Management API. You can do this in Kinde by going to Settings > APIs > Kinde Management API and then toggling on your application under the Applications tab.

Authentication Setup

The error message suggests there might be an issue with your authentication credentials. Let's review the correct setup process:

Add a machine-to-machine application for API access and copy the necessary credentials.

Use these credentials to call the Kinde token endpoint. Here's an example in NodeJS:
Plain Text
const getAccessToken = async () => {
   try {
   const searchParams = {
   grant_type: "client_credentials",
   client_id: "<your_client_id>",
   client_secret: "<your_secret_id>",
   audience: "https://<your_subdomain>.kinde.com/api"
   };

const res = await fetch("https://<your_subdomain>.kinde.com/oauth2/token", {
   method: "POST",
   headers: {
   "Content-Type": "application/x-www-form-urlencoded"
   },
   body: new URLSearchParams(searchParams)
   });
   const token = await res.json();
   console.log({token});
   } catch (err) {
   console.error(err);
   }
  };

Use the obtained access token to call the Kinde management API:
Plain Text
const getUsers = async () => {
   const accessToken = await getAccessToken();

const headers = {
   'Accept': 'application/json',
   'Authorization': `Bearer ${accessToken}`
   };
   try {
   const res = await fetch('https://<your_subdomain>.kinde.com/api/v1/users', {
   method: 'GET',
   headers: headers
   });
   const data = await res.json();
   console.log({data});
   } catch (err) {
   console.error(err);
  }

Troubleshooting

If you're still encountering the "Invalid credentials" error after following these steps, double-check the following:

  • Ensure you've correctly copied and pasted your client_id and client_secret.
  • Verify that your application has the necessary permissions in the Kinde dashboard.
  • Check that you're using the correct subdomain in your API calls.
IT's working now but found a bug / typo. Using the kinde/management-api-js when retrieving user identities, the response is structured as
Plain Text
{
  code: string,
  message: string,
  has_more: boolean,
  identities: Array<Object>
}


But I can't do something like
Plain Text
const ids = await Users.getUserIdentities({})
console.log(ids.identities)


Because it creates an error : Property 'identities' does not exist on type 'get_identities_response'.
Add a reply
Sign up and join the conversation on Discord