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
Is your feature request related to a problem? Please describe the problem.
For a long time there was an undocumented way to get an access token from the current session using code like [Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance...
This is option now removed by #3789 because of assembly isolation
Describe the solution you'd like.
I would like a command that returns a cached or fresh (with -Fresh flag) access token as a secure string, so we can tell people to use that. And have that documented.
Maybe even with a way to specify the scopes, so it can also be used the get tokens for other applications.
Why not provide a way that just returns set token as a secure string?
Authentication is one of the most difficult things to grasp, being able to provide a way for users to just get an access token without tricks seems like a nice addition.
+1, thanks for the ping. SecureString sounds right: Connect-MgGraph -AccessToken already takes one, so tokens could move between sessions without unwrapping. One thought on -Scope: a different scope is a new request through the credential (and possibly a prompt), not a cache read, so it may be worth keeping separate from cached-or-fresh. Confirmed the GraphSession trick now fails on 2.41.0 with "Unable to find type", which makes your case.
Az CLI and PowerShell modules already have this capability and it's really useful. While it's possible to use Get-AzAccessToken it would be useful if this was embedded into the graph module rather than having to install a second module set + additional Auth, just for this command
Quick data point while this is open: on 2.41.1 and 2.41.2 (PS 7.6.7) the GraphSession type literal still fails, and the request-header route works as an interim. I tested with a fabricated token passed to Connect-MgGraph -AccessToken, so Graph returned 401, but the outgoing request carried the session token:
$params=@{
Uri='v1.0/me'OutputType='HttpResponseMessage'SkipHttpErrorCheck=$true# app-only sessions get an error from /me, but the request still carries the token
}
$token= (Invoke-MgGraphRequest@params).RequestMessage.Headers.Authorization.Parameter
That leaves a plain string in a variable, which is the logging risk a SecureString-returning Get-MgAccessToken would avoid, so I still think the command is worth adding.
For history: this is the same ask as #2023 (open since May 2023, 23 comments). The main objection there was that an exposed token invites reuse against other APIs and then fails under Conditional Access or CAE; a SecureString return plus a doc note that the token is bound to the current Graph session answers most of it. The HttpResponseMessage header route was also first posted there, in April 2024.
Activity
svrooij commentedon Sep 30, 2026
Mike Crowley (@Mike-Crowley) something like this ☝️
Mike-Crowley commentedon Sep 30, 2026
+1, thanks for the ping. SecureString sounds right: Connect-MgGraph -AccessToken already takes one, so tokens could move between sessions without unwrapping. One thought on -Scope: a different scope is a new request through the credential (and possibly a prompt), not a cache read, so it may be worth keeping separate from cached-or-fresh. Confirmed the GraphSession trick now fails on 2.41.0 with "Unable to find type", which makes your case.
ld0614 commentedon Oct 6, 2026
Az CLI and PowerShell modules already have this capability and it's really useful. While it's possible to use Get-AzAccessToken it would be useful if this was embedded into the graph module rather than having to install a second module set + additional Auth, just for this command
Mike-Crowley commentedon Oct 14, 2026
Quick data point while this is open: on 2.41.1 and 2.41.2 (PS 7.6.7) the
GraphSessiontype literal still fails, and the request-header route works as an interim. I tested with a fabricated token passed toConnect-MgGraph -AccessToken, so Graph returned 401, but the outgoing request carried the session token:That leaves a plain string in a variable, which is the logging risk a SecureString-returning
Get-MgAccessTokenwould avoid, so I still think the command is worth adding.🤖 Drafted and posted by Claude (Claude Code) on behalf of Mike Crowley (@Mike-Crowley).
Mike-Crowley commentedon Oct 19, 2026
For history: this is the same ask as #2023 (open since May 2023, 23 comments). The main objection there was that an exposed token invites reuse against other APIs and then fails under Conditional Access or CAE; a SecureString return plus a doc note that the token is bound to the current Graph session answers most of it. The
HttpResponseMessageheader route was also first posted there, in April 2024.🤖 Claude Mythos 5.1 (max effort) via Claude Code