I am trying to retrieve the Azure AD user given a subject id (sub
) in an Azure AD registered application. I know the application and the sub
, but I cannot find a way to retrieve the oid
or upn
for the actual user using this information.
Digging around I cannot find anything on retrieving User based on sub
and application id in the docs:
https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0
When reading about the id token it is suggested that sub + tid + oid
should be used for synchronizing across services. And looking at sub
more specifically says:
The principal about which the token asserts information, such as the user of an app. This value is immutable and cannot be reassigned or reused. It can be used to perform authorization checks safely, such as when the token is used to access a resource, and can be used as a key in database tables. Because the subject is always present in the tokens that Azure AD issues, we recommend using this value in a general-purpose authorization system. The subject is, however, a pairwise identifier - it is unique to a particular application ID. Therefore, if a single user signs into two different apps using two different client IDs, those apps will receive two different values for the subject claim.
- https://learn.microsoft.com/sv-se/azure/active-directory/develop/id-tokens
- https://learn.microsoft.com/sv-se/azure/active-directory/develop/access-tokens
I also had a look around SO and only found this related answer but it seems to go from OID to SUB:
Getting User's Token Subject Identifier (sub) From Within Azure AD
Can I query the Graph API using application identifier and subject identifier to find the object identifier or upn?
If it is not possible using the Graph API. Is there any way at all to backtrack which Azure AD user has a given subject id for an application?