Can I generate Azure AD Client Credentials Secrets using an API?

Viewed 804

I want to use my Azure AD App Registration to create multiple Client Secrets. I am stuck on two questions and haven't been able to find any documentation around these:

  1. Is there an API (Graph, or any other) which I can use to automate generation and deletion of the Client Secrets?
  2. Is there a limit on how many Client Secrets there can be within a single app?
2 Answers

Is there an API (Graph, or any other) which I can use to automate
generation and deletion of the Client Credentials Secrets?

You can generate the client secret by calling Add Password api, or delete the client secret by calling remove Password api.

Please note that {id} in the api is the Object ID.

enter image description here

Is there a limit on how many Client Secrets there can be within a single app?

It depends on whether your application supports personal account login. If your application supports personal account login, you can only create two client secrets at most.

If your application only supports work account login, there will be no limit to the number of client secrets created.

You can learn about or modify the account types supported by the application by viewing the manifest of the application. It is the signInAudience attribute in the manifest.

You can use the below sample code for the generating the application credentials :

var graphClient = new GraphServiceClient( authProvider );

var passwordCredential = new PasswordCredential
{
    DisplayName = "Password name"
};

await graphClient.Applications["{application-id}"]
    .AddPassword(passwordCredential)
    .Request()
    .PostAsync();

API Reference

Related