I used the token generated by msal to access the openai api, but was prompted not to have permission

xiaoming chen 0 Reputation points
2023-05-24T14:03:45.6+00:00
var msal = require('@azure/msal-node');

; (async () => {

  const msalConfig = {

    auth: {

      clientId: 'cca04989-623d-47c0-80a9-*******',

      authority: "https://login.microsoftonline.com/a830e50c-888b-41fc-9ca0-*******/", 

      clientSecret: 'VV38Q~zESpRrDkvmOslID************'

    },

  }

  const msalInstance = new msal.ConfidentialClientApplication(msalConfig);

  var res = await msalInstance.acquireTokenByClientCredential({ scopes: ['https://cognitiveservices.azure.com/.default'] })

  console.log('res', res)

})()

3181684936635_.pic

3171684936635_.pic

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,107 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,326 questions
{count} votes

1 answer

Sort by: Most helpful
  1. 2023-05-24T18:17:17.0666667+00:00

    Hello @xiaoming chen , as stated by VasimTamboli, you need to add proper application, not delegated permissions as displayed in your latest comment. This because (in your code) you're authenticating as an application, not a user. For more information take a look to Types of permissions and Authentication.

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.