Introduce @me.id and @me.userName to simplify working with the current user
See original GitHub issueDiscussed in https://github.com/pnp/cli-microsoft365/discussions/3055
<div type='discussions-op-text'>Originally posted by waldekmastykarz February 14, 2022
We have commands that require you to specify the user’s ID or name. Currently, there’s no way to easily specify information about the current user. There are some workarounds like retrieve the user name from the status
command. If you need user’s ID you’d pass the name to the aad user get
command. We could also consider custom implementations in the different commands to introduce specific options like --me
. But this is all too cumbersome.
Since we have information about the current user already available in the access token, we could introduce tokens like @me.id
and @me.userName
that we’d replace with the corresponding information, similarly like we pass content from files. This would free us from having to have command-specific implementations and would make it easier to work with data specific to the current user.
What do you think @pnp/cli-for-microsoft-365-maintainers?</div>
This should be implemented just before we replace @
tokens with file contents: https://github.com/pnp/cli-microsoft365/blob/21e7f85ee4f6e0e77e3872bca56f11e70bcbb423/src/cli/Cli.ts#L165. In the implementation we need to consider both delegated and app-only auth. @me
tokens should work only in delegated mode. In app-only auth they should be replaced with empty values to avoid considering appId a user ID.
Together with this change we should update docs and add a new section after https://pnp.github.io/cli-microsoft365/user-guide/using-cli/#passing-complex-content-into-cli-options that explains which tokens are available and how they can be used.
Checklist:
- code
- test
- docs
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:7 (7 by maintainers)
I am going to pick this up
We’ve got it here: https://github.com/pnp/cli-microsoft365/blob/de62fbe209ee4438efc4072ef5887bbc51ec0d0a/src/utils/validation.ts#L8-L12