cli-microsoft365
cli-microsoft365 copied to clipboard
New feature: using M365 cli access token in local dev
If you are developing against SharePoint API outside of browser context, you need to create an application registration with a self signed certificate and add application permissions via Entra Admin center. See https://pnp.github.io/pnpjs/getting-started/#authentication. And in production you would actually need to do this in a proper way via Managed Identity. I see this as a tedious development experience and a hurdle to for a new developer.
If you're working with Graph API, you can actually use the token provided by Az CLI in your local development. The token provided by Az CLI was working with SharePoint API about two years ago, but stopped working at some point last year if I recall correctly. Az CLI uses by default a first party Microsoft app registration if I'm not mistaken.
So I decided to take a look at how @azure/identity works with AzureCliCredentials and noticed it's a simple CLI wrapper. Then I blatantly copy pasted the implementation to work with m365 cli and have been using this in my own projects for the time being.
I've currently implemented this only in TypeScript. See my sample here to test this in your environment.
So technically it's a wrapper against m365 util accesstoken get, and is piggybacking on the idea that most developers usually have PnP Management Shell app registration already done and thus if you have m365 cli access, you have an easy way to develop with your own credentials.
I see this as a feature that would make local testing and development much more developer friendly. I think there would be use for this as a pnp project, but I am not sure where and how should this be packaged.