How to connect Exchange Online using oauth access token

Piyumi Perera 101 Reputation points
2023-02-02T06:41:35.25+00:00

Hi,

I have a requirement to connect exchange using access token. So following documentation is found about using access token to Connect ExchangeOnline.

https://www.michev.info/Blog/Post/4249/connecting-to-exchange-online-powershell-by-passing-an-access-token#comment-21247

According to this documentation, I used auth code flow to get the access token since delegate permission is added here. I am getting following error when trying to connect.

Connect-ExchangeOnline -UserPrincipalName {userprincipalname} -AccessToken {access_token}

User's image

Can someone help me to fix the error?

Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,176 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,054 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 43,931 Reputation points
    2023-02-02T17:25:08.92+00:00

    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query.

    The following steps describe how to connect to Exchange Online using an OAuth access token:

    1. Take advantage of the Google API Console to first obtain OAuth 2.0 credentials.
    2. the Google Authorization Server's access token next.
    3. Next, trade your authorisation code for access and refresh tokens.
    4. Once you receive your refresh and access tokens, sign in to Exchange Online using them.
    5. Finally, to control the mailbox, utilize the Exchange Online PowerShell cmdlets.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.