My manager wanted a script that lists users through Microsoft Graph without using anyone's account. I registered an application, gave it read access to users only, created a short-lived secret, proved it cannot read anything else, then rotated the secret and checked that the old one stopped working. It is a test tenant with fictional accounts.
Tenant names, IDs and secrets are hidden behind black boxes, and the red marks point out what matters in each screenshot.
The big picture
Skill: Registering an application in Microsoft Entra ID, giving it least-privilege API permissions, and managing its credentials.
What this solves: Scripts and services need to call APIs without a person signing in. If they get too many permissions, or a secret that never expires, one leaked credential can expose the whole tenant.
The approach: least-privilege application identity with a managed credential lifecycle. The app gets only the permission it needs, admin consent is deliberate, secrets are short-lived and rotated, and every use is traceable in the logs.
Solutions used: an Entra app registration, its service principal (enterprise application), Microsoft Graph application permissions with admin consent, a client secret with a short expiry, secret rotation, and the service principal sign-in logs.
Registering the app
I registered app-reporting-script for my organization only, with no redirect URI. The Overview page holds the client and tenant IDs, which I hid. It also links to the managed application with the same name, which is the service principal: the identity that actually signs in, created from the registration.

The service principal and its owner
On the enterprise application side, the Owners page lists an owner with the role Configuration Owner. The page also points out that the owners of the app registration are kept on a separate list.

Granting only what the script needs
I added a single permission: Microsoft Graph User.Read.All as an Application permission. Admin consent is required for it, and I granted it, so the status shows Granted. Nothing else is configured.

Creating a short-lived secret
I created a client secret with a 90 day expiry, which gives the date 31 January 2027. The value is shown only once at creation, so the screenshot shows the row with the value and ID hidden.

Calling Graph as the app
In PowerShell I requested a token with the client credentials flow and then asked Graph for one user. The call succeeded: Graph answered with a response and a link to the next page. The output does not show the user record itself.

Proving it cannot read more
The same token against the groups endpoint is refused with 403 Forbidden, because the app was never given a groups permission.

Rotating the secret
I created a second secret and deleted the first. The list now shows a single secret, reporting-script-secret-2, with its value masked.

Checking the old secret is dead
Using the old secret, the token request fails with AADSTS7000215: Invalid client secret provided.

Reading the service principal sign-ins
The service principal sign-in logs show one success and one failure for the app, matching my two token requests with the working and the old secret.

Findings and recommendations
An application permission has no user in the way. User.Read.All is narrow compared with a directory-wide role, but it still reads every user's full profile. Give a script only the permission it needs, and review it regularly.
The secret was typed in clear text on screen. It appeared in the console and in the portal right after creation, and I had to hide it in these screenshots. For production, I recommend a certificate or a managed identity instead of a client secret. The portal itself recommends a certificate.
Short expiry helps, but rotation needs a process. A 90 day secret limits the damage from a leak only if someone replaces it before it expires and removes the old one, as I did here.
Deleting the old secret worked straight away. The old secret was rejected on the next request.
The failure row is an aggregate. It starts at 12:40:55 UTC, a little before the console error at 12:42:15, so it may group more than one failed attempt. I did not expand it.
Not captured: the permission before consent (the Not granted state), the enterprise applications list, and the user record in the Graph response.
