Enhance token management and add Disconnect-AzResourceGraph function#5
Merged
PalmEmanuel merged 2 commits intomainfrom Jun 18, 2025
Merged
Enhance token management and add Disconnect-AzResourceGraph function#5PalmEmanuel merged 2 commits intomainfrom
PalmEmanuel merged 2 commits intomainfrom
Conversation
Contributor
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves token management and adds a new cmdlet to disconnect from Azure Resource Graph by clearing cached tokens.
- Introduces
Disconnect-AzResourceGraphto reset in-memory session state. - Enhances
Connect-AzResourceGraphwith aManagementEndpointparameter, token cache configuration, and user identity handling. - Refactors token expiry/scope checks in
Test-AzureTokenand tweaks the interactive path inAssert-AzureConnection.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/Public/Disconnect-AzResourceGraph.tests.ps1 | Adds tests validating that Disconnect-AzResourceGraph clears session state. |
| CHANGELOG.md | Updates version history; adds a fixed section and reorganizes releases. |
| AzResourceGraph/Public/Disconnect-AzResourceGraph.ps1 | Implements new Disconnect-AzResourceGraph cmdlet. |
| AzResourceGraph/Public/Connect-AzResourceGraph.ps1 | Adds ManagementEndpoint parameter and enriches token splatting logic. |
| AzResourceGraph/Private/Test-AzureToken.ps1 | Switches to UTC comparisons and includes scope fallback in token checks. |
| AzResourceGraph/Private/Assert-AzureConnection.ps1 | Removes extra parameters on interactive reauthorization. |
Comments suppressed due to low confidence (6)
AzResourceGraph/Public/Connect-AzResourceGraph.ps1:96
- The new
ManagementEndpointparameter lacks a type annotation (e.g.[string]) and no Parameter attribute for Mandatory or Position. Consider declaring a[string]type and adding appropriate[Parameter(...)]attributes for each ParameterSet to enforce valid input.
$ManagementEndpoint = 'https://management.azure.com'
AzResourceGraph/Public/Connect-AzResourceGraph.ps1:36
- [nitpick] Consider adding a
ValidateSetattribute to theManagementEndpointparameter to restrict values to known Azure cloud endpoints (e.g., global, China, USGov). This prevents typos and improves discoverability.
Endpoint used for management. This is used for the Audience claim when authenticating to Azure.
AzResourceGraph/Public/Disconnect-AzResourceGraph.ps1:2
- [nitpick] The synopsis mentions clearing the cached access token in memory but omits that
TokenSourceis reset to 'Global'. Consider updating the help text to list all module-scoped variables that this cmdlet resets.
.SYNOPSIS
tests/Unit/Public/Disconnect-AzResourceGraph.tests.ps1:23
- Add an assertion to verify that
$script:TokenSourceis reset (e.g., to 'Global') after callingDisconnect-AzResourceGraphto ensure full state clearance.
$script:TokenSplat.Keys.Count | Should -be 0
CHANGELOG.md:11
- The changelog entry for 0.1.1 omits the new
Disconnect-AzResourceGraphaddition under 'Added' and reuses the same date as 0.1.0. Please include the new function in the 'Added' section and correct the release date sequencing.
## [0.1.1] - 2025-05-14
AzResourceGraph/Private/Assert-AzureConnection.ps1:68
- Removing
ClientIdwhenInteractiveis present may drop needed identity info for token renewals. Verify whether this removal is intentional or if a different key (e.g.,UserName) should be pruned instead.
$LocalTokenSplat.Remove('ClientId')
PalmEmanuel
approved these changes
Jun 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Improve token handling by refining parameter management and adding a new function to disconnect from Azure Resource Graph, clearing cached tokens.