GeraldBriyolan
New Contributor II

I have tried using this document I got the access token (been authenticated from databricks) but when i tried to use it to get the users or the workspace it shows error.

      const auth = new GoogleAuth();
      const idTokenClient = await auth.getIdTokenClient(audience);
      const headers = await idTokenClient.getRequestHeaders();
      const oidc_token = headers.Authorization.replace('Bearer ', '');

      const token_exchange_url = `https://2153434890.0.gcp.databricks.com/oidc/v1/token`;
      const formData = new URLSearchParams({
        grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
        requestedTokenType: 'urn:ietf:params:oauth:token-type:access_token',
        subject_token: oidc_token,
        subject_token_type: 'urn:ietf:params:oauth:token-type:jwt',
        scope: 'all-apis',
      });

      const response = await axios.post(token_exchange_url, formData, {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        timeout: 30000,
      });

      const access_token = response.data.access_token;

      if (!accessToken) return { success: false, message: 'Invalid Credentials' };

      const api = `https://accounts.gcp.databricks.com/api/2.0/accounts/${databricksAccountId}/workspaces`;
      const headers = {
        Authorization: `Bearer ${accessToken}`,
        'Content-Type': 'application/json',
      };

      const response = await axios.get(api, {
        headers,
        timeout: 15000, 
      });

      const workspaces = await response.data.map((workspace) => {
        return {
          workspaceId: workspace.workspace_id,
          workspaceName: workspace.workspace_name,
          regionName: workspace.location,
          workspaceUrl: `${workspace.deployment_name}.gcp.databricks.com`,
          workspaceTier: workspace.pricing_tier,
        };
      });

 I have attached the code if i am done any mistake in the code kindly lent me know and tell me a solution for this issue.