You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding the ability to surface the access token used by the connection #2023
Originally posted by glennvanrymenant May 15, 2023
Would it be possible to add the ability to surface the access token used by the connection (Connect-MgGraph).
I prefer to call the Graph API directly (using Invoke-MgGraphRequest rather than the specific cmdlets) but ideally I would like call the Graph API directly with Invoke-WebRequest using the access token of the Graph SDK connection.
Read: I want to piggy-back on the auth part of the module (mainly when leveraging delegated permissions as using the auth of the module is easier than writing and maintaining your own authorization code flow functions).
Reacted by Merill Fernando, Roel van der Wegen, shunkin, Jim Sykora, ChristopheLux, Jolv95, Joe Agler and Bastien Perez
Would also like to see the MS.Graph powershell module follow the same patterns as the other first party Microsoft Azure modules.
As Merill Fernando (@merill) has already pointed out.
Hoping someone can progress on this. There are many tools out there in the community currently stuck with using MSAL.PS because its to hard to move away from it. Please get some work started to build the Get-MgAccessToken cmdlet. Darrel (@darrelmiller)Petr Hollay (@petrhollayms)
Reacted by Nickolaj Andersen, David O'Brien and Magnus Mårtensson
I don't understand why we (the customers and community) have to go through these discussions with every single team that manages a CLI or PowerShell module.
As Merill Fernando (@merill) mentioned, many other Microsoft tools already support this. Darrel (@darrelmiller) please consider exposing this capability like so many other tools already do.
I would also like to advocate for this change, as it would drastically help improve some of my pipelines. Currently, https://github.com/SCOMnewbie/PSMSALNet works quite well, but I would prefer to use a supported, MS-backed, module :)
Would that not only get the token with the claims for what you asked for? If I want to do something else, I'd need a different token.
Either way, I second (fifth, sixth whatever) this request. I am in the exact same situation now. I can auth with Azure and then use Get-AzToken, but "it's not the right context for that". I don't want to go to the Azure context to get the token for my Entra context.
How about this method. Ask Entra for a token by making a POST to:
Petr Hollay (@petrhollayms), Merill Fernando (@merill) since this is still open and hasn't been closed, is there any progress you can share? Can we expect the module to support generating/exposing tokens, or do we continue to rely on workarounds to grab the token?
I struggle to understand why the hesitation for just PowerShell alone. It's not a matter of difficulty, that excuse can't work. We can easily get it done already in PowerShell, and it's super easy in C#, plus we can do C# things in PowerShell, and there are other easy libraries for MSAL.NET. Can't justify this any further. It is justified and please acknowledge and do something about this.
Reacted by Magnus Mårtensson, Merill Fernando and Sebastian Wiszowaty
Is this PowerShell module a Graph SDK that aligns in spirit to the rest of the Graph SDKs like C#, JS, etc that is intended for developers or is this module's primary audience non-devs?
If it's an SDK, why not provide complete access to the underlying MSAL library that the other Graph libraries like C# and JS do.
Darrel (@darrelmiller) I believe in the past you were leaning towards this module being an SDK and the users of this module being devs → #513 (comment)
Darrel (@darrelmiller) It seems like a perfect point has been made. You stated that PowerShell users are developers and should not get special treatment vs other programming language developers. But now here in this topic, PowerShell developers are being treated differently. Can we please have an update on this topic?
This came back last month as #3806 (Get-MgAccessToken returning a SecureString), prompted by the assembly isolation in 2.41.0 (#3789): the unofficial [Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance route no longer works on PowerShell 7, because that type now lives in a private AssemblyLoadContext. The Invoke-MgGraphRequest -OutputType HttpResponseMessage header trick posted above still works on 2.41.2 (checked with a fabricated token, so no sign-in involved), but it leaves a plain string in a variable, which is the main thing a SecureString-returning cmdlet would fix. Linking the two so the history here, including the 2023 concerns about token reuse, is visible there.
This looks like it was closed by accident a few hours ago, and I think it needs reopening.
#3833 merged at 00:09:09Z today and closed this issue and #3806 as completed. #3895 then reverted #3833 in full at 01:48:31Z, 99 minutes later, to restore the Authentication assembly isolation. Get-MgAccessToken is not in main: searching the tree for the cmdlet name returns no match in source.
So the feature is not shipped, but the two issues asking for it read as resolved. Anyone subscribed here since 2023 now believes this landed.
Nothing to do with the work itself — the revert reason is sound and Ramses Sanchez-Hernandez (@ramsessanchez) already wrote the design for the follow-up in the revert body. This is only about the issue state.
Activity
mortenlerudjordet commentedon Jul 19, 2023
Would also like to see the MS.Graph powershell module follow the same patterns as the other first party Microsoft Azure modules.
As Merill Fernando (@merill) has already pointed out.
glennvanrymenant commentedon Nov 23, 2023
What is the status of this request? Looks orphaned 🤔.
JankeSkanke commentedon Apr 9, 2024
Hoping someone can progress on this. There are many tools out there in the community currently stuck with using MSAL.PS because its to hard to move away from it. Please get some work started to build the Get-MgAccessToken cmdlet.
Darrel (@darrelmiller) Petr Hollay (@petrhollayms)
davidobrien1985 commentedon Apr 27, 2024
I don't understand why we (the customers and community) have to go through these discussions with every single team that manages a CLI or PowerShell module.
As Merill Fernando (@merill) mentioned, many other Microsoft tools already support this. Darrel (@darrelmiller) please consider exposing this capability like so many other tools already do.
Thank you!
DanielBradley1 commentedon Apr 27, 2024
I would also like to advocate for this change, as it would drastically help improve some of my pipelines. Currently, https://github.com/SCOMnewbie/PSMSALNet works quite well, but I would prefer to use a supported, MS-backed, module :)
davidobrien1985 commentedon Apr 30, 2024
Someone on Twitter pointed me to this here:
This indeed works.
noopman commentedon May 3, 2024
Would that not only get the token with the claims for what you asked for? If I want to do something else, I'd need a different token.
Either way, I second (fifth, sixth whatever) this request. I am in the exact same situation now. I can auth with Azure and then use Get-AzToken, but "it's not the right context for that". I don't want to go to the Azure context to get the token for my Entra context.
How about this method. Ask Entra for a token by making a POST to:
[Uri]"https://login.microsoftonline.com/$(Get-TenantId)/oauth2/token"
My challenge becomes that we need a "resource" in the body. This works well when asking for a token to, for example, call an API.
glennvanrymenant commentedon Jul 30, 2024
Petr Hollay (@petrhollayms), Merill Fernando (@merill) since this is still open and hasn't been closed, is there any progress you can share? Can we expect the module to support generating/exposing tokens, or do we continue to rely on workarounds to grab the token?
JeremyTBradshaw commentedon Oct 24, 2024
Darrel (@darrelmiller) Petr Hollay (@petrhollayms) Merill Fernando (@merill) glennvanrymenant Carol Kigoonya (@CarolKigoonya) Magnus Mårtensson (@noopman) Jan Ketil Skanke [MVP] (@JankeSkanke) trying not to miss anyone who's been asking for this...
https://learn.microsoft.com/en-us/entra/msal/dotnet/advanced/powershell-support - this page seems to state it outright. MS Graph PowerShell SDK is the official PowerShell thing that wraps in MSAL.NET. If we want to do things like SASL XOAuth2 for SMTP/IMAP/POP, we could use MailKit as officially recommended but then we need a way to obtain our own access token. We can do all this using C# and other programming languages that have been blessed by MSAL.NET, but in PowerShell we have to go unsupported to get our hands on an access token. This module is the correct place for this to finally happen.
I struggle to understand why the hesitation for just PowerShell alone. It's not a matter of difficulty, that excuse can't work. We can easily get it done already in PowerShell, and it's super easy in C#, plus we can do C# things in PowerShell, and there are other easy libraries for MSAL.NET. Can't justify this any further. It is justified and please acknowledge and do something about this.
merill commentedon Oct 26, 2024
That's a good point you raise JeremyTBradshaw.
Is this PowerShell module a Graph SDK that aligns in spirit to the rest of the Graph SDKs like C#, JS, etc that is intended for developers or is this module's primary audience non-devs?
If it's an SDK, why not provide complete access to the underlying MSAL library that the other Graph libraries like C# and JS do.
Darrel (@darrelmiller) I believe in the past you were leaning towards this module being an SDK and the users of this module being devs → #513 (comment)
JeremyTBradshaw commentedon Nov 13, 2024
Darrel (@darrelmiller) It seems like a perfect point has been made. You stated that PowerShell users are developers and should not get special treatment vs other programming language developers. But now here in this topic, PowerShell developers are being treated differently. Can we please have an update on this topic?
Mike-Crowley commentedon Oct 19, 2026
This came back last month as #3806 (
Get-MgAccessTokenreturning a SecureString), prompted by the assembly isolation in 2.41.0 (#3789): the unofficial[Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instanceroute no longer works on PowerShell 7, because that type now lives in a private AssemblyLoadContext. TheInvoke-MgGraphRequest -OutputType HttpResponseMessageheader trick posted above still works on 2.41.2 (checked with a fabricated token, so no sign-in involved), but it leaves a plain string in a variable, which is the main thing a SecureString-returning cmdlet would fix. Linking the two so the history here, including the 2023 concerns about token reuse, is visible there.🤖 Claude Mythos 5.1 (max effort) via Claude Code
earbona23 commentedon Nov 5, 2026
This looks like it was closed by accident a few hours ago, and I think it needs reopening.
#3833 merged at 00:09:09Z today and closed this issue and #3806 as completed. #3895 then reverted #3833 in full at 01:48:31Z, 99 minutes later, to restore the Authentication assembly isolation.
Get-MgAccessTokenis not inmain: searching the tree for the cmdlet name returns no match in source.So the feature is not shipped, but the two issues asking for it read as resolved. Anyone subscribed here since 2023 now believes this landed.
Nothing to do with the work itself — the revert reason is sound and Ramses Sanchez-Hernandez (@ramsessanchez) already wrote the design for the follow-up in the revert body. This is only about the issue state.
Allow getting an access token using the broker (microsoftgraph#3833)