0

I want to expose API with AAD token based authentication using Clients Id and secret.

User how need access on API will request with Clients ID. If we whitelist client ID for API access then API can be accessible using Client ID and Client Secret.

Like Kusto services accesss.

So need help how we can configure this API using Azure service's.

Chauncy Zhou
  • 1,010
  • 1
  • 5
  • 10
Raj Hiray
  • 1
  • 1
  • See https://stackoverflow.com/questions/38494279/how-do-i-get-an-oauth-2-0-authentication-token-in-c-sharp – auburg Jul 22 '20 at 09:51

1 Answers1

0

According to your question, you expose an api protected by Azure, and then you need to request an access token using the client id and client secret to access the api.

First, you must create another application as a client application, then use this client application to access the api application, and you need to grant application permissions to the client application. It is recommended that you use the client credential flow.

Next, you need to define application permissions by editing the api application manifest. This is a example.

Then, grant application permissions to the client application. enter image description here

The next two steps are done using the client application:

1.First, you need to obtain the administrator's consent:

GET https://login.microsoftonline.com/{tenant}/adminconsent?
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&state=12345
&redirect_uri=http://localhost/myapp/permissions

enter image description here

2.Request an access token using client id and client secret:

POST /{tenant}/oauth2/v2.0/token HTTP/1.1           //Line breaks for clarity
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id=535fb089-9ff3-47b6-9bfb-4f1264799865
&scope=api://your-app-id/.default
&client_secret=qWgdYAmab0YSkuL1qKv5bPX
&grant_type=client_credentials

enter image description here

Try using the token to access your API.

Carl Zhao
  • 8,543
  • 2
  • 11
  • 19