Using access tokens with Connect-ExchangeOnline

Version 3.1.0 of the ExchangeOnlineManagement modules introduced a new option in the Connect-ExchangeOnline cmdlet. You can now pass it an access token.

Here’s how I went about using it.

First, I created an App Registration with this delegated permission:

Did the admin consent. And under “Authentication” I enabled public client flows. (This is not strictly needed, but I use device code flow to authenticate later so it’s needed).

I also went to the corresponding Enterprise Application and limited it to my admin account only.

Next, I used the function I created a while ago for authenticating using the device code flow.

I ran it thus:

I got the scope from this link.

This should do the following:

And once I authenticate by visiting the URL and entering the device code, the $result object should have the access token.

I can now connect thus:

And that works!