Skip to content

🩹 [Patch]: Prevent Concurrent Access Token Refresh with Mutex Lock #393

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

Merged
merged 31 commits into from
Jul 3, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 31, 2025

This pull request introduces significant updates to the GitHub authentication and API handling mechanisms, improving token management, adding support for GitHub App private keys, and enhancing concurrency handling. The changes also include adjustments to data types and configurations for better precision and compatibility.

Authentication Updates

  • Added support for GitHub App private key handling by introducing a new PrivateKey property in AppGitHubContext and ensuring it is securely processed during authentication.
  • Enhanced token refresh logic to handle both user access tokens and GitHub App PEM tokens, with mutex-based concurrency control for token updates.

API Handling Improvements

  • Removed redundant token refresh logic from Invoke-GitHubAPI and centralized it in the context resolution process for better maintainability.

Configuration and Type Adjustments

  • Changed AccessTokenGracePeriodInHours from int to double for increased precision in token expiration calculations.
  • Updated time-related calculations to use [datetime]::Now instead of Get-Date for consistency across the module.

…evention

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] 🩹 [Patch]: Prevent Concurrent Access Token Refresh with Mutex Lock 🩹 [Patch]: Prevent Concurrent Access Token Refresh with Mutex Lock May 31, 2025
@Copilot Copilot AI requested a review from MariusStorhaug May 31, 2025 16:15
Copilot finished work on behalf of MariusStorhaug May 31, 2025 16:15
- Created TEMPLATE.ps1 for structuring Pester tests with authentication cases.
- Added Teams.Tests.ps1 to test GitHub Teams API functionalities, including team creation, retrieval, updating, and deletion.
- Introduced Users.Tests.ps1 to validate user-related API calls, such as fetching user details and updating user information.
- Implemented Variables.Tests.ps1 to cover GitHub repository and organization variable management, including setting, updating, and removing variables.
…and adjust context resolution logic in Resolve-GitHubContext for improved token handling
…ensure proper conversion from plain text to SecureString
… for cleaner output and improved verbosity handling
… to prevent concurrent token refresh operations
…oken with improved error handling and mutex management
…x handling, timeout parameter, and refined token validity checks
…itHubContext and adjust return value in process block
…oved context retrieval in Update-GitHubUserAccessToken
…serAccessToken with improved validity checks and mutex handling
…rAccessToken to use current datetime for improved accuracy
…rAccessToken and improve token expiration checks in GitHubContext.Types
- Created TEMPLATE.ps1 for standardized test structure.
- Implemented Teams.Tests.ps1 to validate GitHub Teams API functionalities, including team creation, retrieval, updating, and deletion.
- Developed Users.Tests.ps1 to test user-related API calls, including user retrieval and updates.
- Established Variables.Tests.ps1 to cover GitHub variable management, including setting, updating, and removing variables for users, organizations, and repositories.
- Added necessary logging and context management for better test output and debugging.
- Ensured compatibility with Pester version 5.7.1 and addressed known code analysis warnings.
@MariusStorhaug MariusStorhaug marked this pull request as ready for review July 3, 2025 20:26
@Copilot Copilot AI review requested due to automatic review settings July 3, 2025 20:26
@MariusStorhaug MariusStorhaug requested a review from a team as a code owner July 3, 2025 20:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@MariusStorhaug MariusStorhaug merged commit bb97530 into main Jul 3, 2025
3 of 5 checks passed
@MariusStorhaug MariusStorhaug deleted the copilot/fix-392 branch July 3, 2025 21:59
@github-project-automation github-project-automation bot moved this from Todo to Done in GitHub PowerShell Module Jul 3, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Module GitHub - 0.33.5 published to the PowerShell Gallery.

Copy link
Contributor

github-actions bot commented Jul 4, 2025

GitHub release for GitHub v0.33.5 has been created.

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

Successfully merging this pull request may close these issues.

🩹 [Patch]: Prevent Concurrent Access Token Refresh with Mutex Lock
2 participants