Skip to content

[Feature Request] Show object ID of the signed in account #22776

@jiasli

Description

@jiasli

Context

Currently, in order to get the object ID of the signed in account, we have to query Microsoft Graph API:

  • User account: az ad signed-in-user show
  • Service principal account: az ad sp show

However, since some tenant (including Microsoft tenant) has Conditional Access policies that block accessing Microsoft Graph with device code (#22629), querying Microsoft Graph API is no longer possible with device code.

Proposed solutions

The result of

  • az login
  • az account show
  • az account list

can show the object ID decoded from the access token.

We can also add a --show-claims parameter to az account get-access-token:

az account get-access-token --show-claims

to decode the access token and show its claims, but his solution is less intuitive.

Manual solution

Object ID can be manually retrieved from the access token:

pip3 install --upgrade pyjwt

az account get-access-token --query accessToken --output tsv |
  tr -d '\n' |
  python3 -c "import jwt, sys; print(jwt.decode(sys.stdin.read(), algorithms=['RS256'], options={'verify_signature': False})['oid'])" 

Metadata

Metadata

Assignees

Labels

Accountaz login/accountAuto-AssignAuto assign by botGraph(doesn't work with label-triggered comments; use Graph.Microsoft instead) az adact-identity-squadfeature-request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions