KindeK
Kinde17mo ago
4 replies
Yvens

add-urls-to-kinde script

After creating a M2M application and setting the client_id and client_secret for my nextjs app. It seems that I can't get the addCallBackUrlToKinde function to work.

I also added the scopes authorization related to application_redirect_uris to m2m application:

Thank you for your help !

async function addCallbackUrlToKinde (token) {
  try {
    const response = await fetch(
      `${process.env.KINDE_ISSUER_URL}/api/v1/applications/${process.env.KINDE_M2M_CLIENT_ID}/auth_redirect_urls`,
      {
        method: 'POST',
        headers: {
          Authorization: `Bearer ${token}`,
          Accept: 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          urls: [`https://${process.env.VERCEL_URL}/api/auth/kinde_callback`]
        })
      }
    )

    if (!response.ok) {
      console.log('response:', response)
      throw new Error(
        `Failed to add callback URL to Kinde: ${response.statusText}`
      )
    }

    const responseData = await response.json()
    console.log(
      `SUCCESS: Callback URL added to Kinde: ${process.env.VERCEL_URL}/api/auth/kinde_callback`,
      responseData
    )
  } catch (error) {
    console.log('error:', error)
    console.error('Failed to add callback URL to Kinde', error)
    throw error
  }
};
Was this page helpful?