Get Accesstoken from Connect-MgGraph

Copper Contributor

Hello there

 

I am using the PowerShell Graph SDK and connecting using the connect-mggraph cmdlet to authenticate to Azure (manual Login).

 

I am assuming, this cmdlet somehow creates something like a temporary app registration and uses this for every further action.

 

Now my question is, if I can somehow get to the access token that the SDK is using on behalf of my User. I then want to make calls to the Graph API with the invoke-restMethod cmdlet

3 Replies
You can use the built-in app, with clientID of 14d82eec-204b-4c2f-b7e8-296a70dab67e. Users will still have to provide credentials though.
@malvinportner
I found these instructions on accessing Graph. He has some examples of how to get a token using Invoke-RestMethod. https://adamtheautomator.com/powershell-graph-api/


In case somebody else has the same question: [System.Text.Encoding]::Ascii.GetString([Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance.MSALToken) | ConvertFrom-Json

But you probably don't need it. Usually Invoke-MgGraphRequest suffices.