question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Finding Applications and Service Principals by ApplicationId

See original GitHub issue

I’m using the fluent API to authenticate a service principal that has full read/write access to the directory and numerous subscriptions. Given that I only have an application id or client id, I’d like to search for the application and service principal in the directory that I use to authenticate against so I can give it access to Key Vault and other resources I’m about to create.

We never reference service principals or applications by its object id or name.

Neither the following works:

string tenantId = "example.onmicrosoft.com";
string clientId = "ead0153a-1234-1234-1234-123456789f98";
string clientSecret = "passsword";

 ServicePrincipalLoginInformation information = new ServicePrincipalLoginInformation();
 information.ClientId = clientId;
 information.ClientSecret = clientSecret;
 AzureCredentials credentials = new AzureCredentials(information, tenantId, AzureEnvironment.AzureGlobalCloud);
var authenticated = Azure.Authenticate(credentials);
var thisApplication = authenticated.ActiveDirectoryApplications.GetById(clientId);
var thisServicePrincipal = authenticated.ServicePrincipals.GetById(clientId);

Shouldn’t there be a method on both authenticated.ActiveDirectoryApplications and authenticated.ServicePrincipals to FindByApplicationId?

The only workaround I have today is to List all the applications, and search for one where the app.ApplicationId matches the clientId. This is very inefficient and extremely slow (it takes minutes) when you have thousands of applications and service principals in the directory.

Is there another way to do this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bloudraakcommented, Sep 9, 2018

In essence, the request is to support the following query using the fluent api. It takes approx. 2 seconds to complete. This is much more efficient.

https://graph.windows.net/example.onmicrosoft.com/servicePrincipals?$filter=appId eq 'ead0153a-1234-1234-1234-123456789f98'
0reactions
xseeseeseecommented, Nov 18, 2019

Close this as GetName works in this case. Please feel free to reopen if any issue persist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apps & service principals in Azure AD
You can find the service principals associated with an application object. ... In the Azure portal, navigate to the application registration ...
Read more >
Create an Azure AD app and service principal in the portal
Register an application with Azure AD and create a service principal · Sign in to the Azure portal. · Search for and Select...
Read more >
Azure: Service Principal ID vs Application ID
Short answer: Application and Service principal are definitely two different things (related in 1:many fashion but definitely different ...
Read more >
Azure: finding your service principal object ID
Type in 'Azure Active Directory' in the search bar. You'll find it listed under Services. ... 3. Select 'Enterprise applications' under Manage on ......
Read more >
Azure AD Service Principals: All you need to know!
Let's first gather the required crucial information from the service principal itself. Which is the Application ID and Tenant ID. Both values ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found