@Sverre Here are the steps you can follow to configure API permissions for your App Registration:
Go to the Azure portal and navigate to your App Registration.
- Click on "API permissions" in the left-hand menu.
- Click on "Add a permission" and select the API you want to configure permissions for (e.g. Azure OpenAI Service or Document Intelligence).
- Select the appropriate permission type (e.g. "Application" or "Delegated") and click "Add permissions".
- Grant admin consent for the new permissions by clicking on "Grant admin consent for {your tenant}".
Once you have configured API permissions for your App Registration, you can use the on-behalf-of flow to acquire bearer tokens for Azure OpenAI Service and Document Intelligence on behalf of logged-in users. Here's an example of how you can implement this flow:
- When a user logs in to your web app, use EasyAuth to authenticate the user and obtain an access token for your web app.
- Use the on-behalf-of flow to exchange the user's access token for a bearer token for Azure OpenAI Service or Document Intelligence.
- Use the bearer token to call the Azure OpenAI Service or Document Intelligence API on behalf of the user.
Here's an example of how you can implement the on-behalf-of flow in C#:
var client = new HttpClient();
var token = await HttpContext.GetTokenAsync("access_token");
var userAssertion = new UserAssertion(token);
var confidentialClient = new ConfidentialClientApplication(clientId, clientSecret, redirectUri, new ClientCredential(clientSecret), null, new TokenCache(), new HttpManager());
var result = await confidentialClient.AcquireTokenOnBehalfOfAsync(scopes, userAssertion);
var bearerToken = result.AccessToken;
Note that you need to replace clientId
, clientSecret
, redirectUri
, and scopes
with the appropriate values for your App Registration and the Azure OpenAI Service or Document Intelligence API you are calling.