thebighadron
thebighadron

Reputation: 155

Is there a way to validate azure app credentials?

Given I have the following info from Azure app registration:

Application (client) ID, Client secret, Directory (tenant) ID, Object ID

Is there a way to check it's a valid credential programmatically (like using curl etc but not powershell)?

Upvotes: 0

Views: 1798

Answers (1)

kavya Saraboju
kavya Saraboju

Reputation: 10859

If you meant to check client secret validity or even the properties of that app ,then please check if the below c# code can be worked around .We can try to query the application and see expiry date of secret. Please grant the app with Directory.Read.All ,Application.Read.All permission to this API for using client credentials flow.

var graphResourceId = "https://graph.microsoft.com";
var applicationId= "";
var ObjectId = "";
var clientsecret = "";
var clientCredential = new ClientCredential(applicationId,secret);
var tenantId = "xxx.onmicrosoft.com";
AuthenticationContext authContext = new AuthenticationContext($"https://login.microsoftonline.com/{tenantId}");

//get accesstoken
var accessToken = authContext.AcquireTokenAsync(graphResourceId, clientCredential).Result.AccessToken;

Uri servicePointUri = new Uri(graphResourceId);
Uri serviceRoot = new Uri(servicePointUri, tenantId);

ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, async () => await Task.FromResult(accessToken));

var app = activeDirectoryClient.Applications.GetByObjectId(appObjectId).ExecuteAsync().Result;

foreach (var passwordCredential in app.PasswordCredentials)
{
    Console.WriteLine($"KeyID:{passwordCredential.KeyId}\r\nEndDate:{passwordCredential.EndDate}\r\n");
}

If you want , you can even request token using curl this way and validate using post man or by checking token in https://jwt.io .

Reference: check client secret expiry using C#

Upvotes: 1

Related Questions