Skip to content

feat: Implement initial token-based authentication flow #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aollivierre
Copy link

feat: Implement initial token-based authentication flow

This commit introduces changes to allow the IntuneManagement tool to utilize a pre-acquired bearer token for authentication, aiming to bypass standard App ID/Secret or interactive login methods.

Modifications include:

  • Added an '-AccessToken' parameter to 'Start-IntuneManagement.ps1'.
  • Updated 'CloudAPIPowerShellManagement.psm1' in the 'Initialize-CloudAPIManagement' function to receive and globally store the provided access token.
  • Iteratively modified 'Invoke-EMAuthenticateToMSAL' in 'Extensions/EndpointManager.psm1' to:
    • Detect and parse the global raw access token.
    • Populate '$global:MSALToken' with the token details.
    • Attempt to configure '$global:EMViewObject.AppInfo' and call 'Set-MSALCurrentApp' with a placeholder ClientId to satisfy MSAL.PS library expectations.
    • Restructure control flow to prevent fallback to interactive login when a token is supplied.

Fix: Prioritize pre-acquired token and prevent re-authentication

This commit addresses an issue where the interactive login prompt was incorrectly triggered even when a pre-acquired bearer token was provided.

The following changes were made:

  • Modified Invoke-GraphRequest in Extensions/MSGraph.psm1 to check for a valid existing $global:MSALToken (not expired) before attempting to call Connect-MSALUser. This prevents unnecessary re-authentication attempts.
  • Updated Connect-MSALUser in Extensions/MSALAuthentication.psm1 to include an early return if $global:MSALToken exists, is derived from $global:RawAccessToken, and is not expired. This ensures that if a valid token has been set via the AccessToken parameter, the function will not proceed with further (interactive) authentication steps.

These changes ensure that the token-based authentication flow is correctly prioritized, preventing the interactive login from appearing when a valid token is already available.

feat: Implement initial token-based authentication flow

This commit introduces changes to allow the IntuneManagement tool
to utilize a pre-acquired bearer token for authentication, aiming
to bypass standard App ID/Secret or interactive login methods.

Modifications include:

- Added an '-AccessToken' parameter to 'Start-IntuneManagement.ps1'.
- Updated 'CloudAPIPowerShellManagement.psm1' in the
  'Initialize-CloudAPIManagement' function to receive and
  globally store the provided access token.
- Iteratively modified 'Invoke-EMAuthenticateToMSAL' in
  'Extensions/EndpointManager.psm1' to:
    - Detect and parse the global raw access token.
    - Populate '$global:MSALToken' with the token details.
    - Attempt to configure '$global:EMViewObject.AppInfo' and call
      'Set-MSALCurrentApp' with a placeholder ClientId to
      satisfy MSAL.PS library expectations.
    - Restructure control flow to prevent fallback to
      interactive login when a token is supplied.

Note: This is an ongoing effort. Current attempts to fully bypass
interactive login prompts when a token is used are still under
investigation.

Fix: Prioritize pre-acquired token and prevent re-authentication

This commit addresses an issue where the interactive login prompt was incorrectly triggered even when a pre-acquired bearer token was provided.

The following changes were made:

-   Modified `Invoke-GraphRequest` in `Extensions/MSGraph.psm1` to check for a valid existing `$global:MSALToken` (not expired) before attempting to call `Connect-MSALUser`. This prevents unnecessary re-authentication attempts.
-   Updated `Connect-MSALUser` in `Extensions/MSALAuthentication.psm1` to include an early return if `$global:MSALToken` exists, is derived from `$global:RawAccessToken`, and is not expired. This ensures that if a valid token has been set via the `AccessToken` parameter, the function will not proceed with further (interactive) authentication steps.

These changes ensure that the token-based authentication flow is correctly prioritized, preventing the interactive login from appearing when a valid token is already available.
@Micke-K
Copy link
Owner

Micke-K commented Jul 28, 2025

Hello,

I'm sorry for long delay. I've been trying to figure this one out.

This is not really in the direction I want to take it at the moment. I'm trying to minimize changes since I'm currently rewriting it completely. I could implement just the token part eg allow your own token.

Also, please create PR to the Development branch.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants