Add Support for Authorization Code Flow Authentication #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
The
Get-GraphTokensfunction currently only supports device code flow for authentication. This can be problematic when an Entra ID tenant has blocked device code flow via a conditional access policy. This PR adds support for authorization code flow, allowing users to choose between device code flow (default) or authorization code flow (Get-GraphTokens -AuthorizationCodeFlow).How does it work?
A browser is opened and a request is made to the
/organizations/oauth2/v2.0/authorizeendpoint. The user is prompted to authenticate. If authentication is successful, the browser is redirected to an HttpListener on localhost where the authorization code is captured.This authorization code is then exchanged in a request to the
/organizations/oauth2/v2.0/tokenendpoint for an access token and FOCI refresh token for the Azure CLI client, which in turn is exchanged in another request to the/organizations/oauth2/v2.0/tokenendpoint for an access token and refresh token for the Microsoft Office client.Usage
Get-GraphTokens -AuthorizationCodeFlow