Checking Azure Service principal expiration using JAVA

Solution 1:

You can use the below Java code to get the service principle's,

GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

ServicePrincipal servicePrincipal = graphClient.servicePrincipals("{id}")
    .buildRequest()
    .get();

Reference : Get servicePrincipal - Microsoft Graph v1.0 | Microsoft Docs

For workaround you can use Microsoft Graph API to get the service principle's

https://graph.microsoft.com/v1.0/servicePrincipals

enter image description here