Skip to content

Commit 2dff5b7

Browse files
🪲 [Fix]: Skip revoke token if token is expired (#488)
## Description This pull request refactors the conditional logic in the `Disconnect-GitHubAccount` function to improve readability and debugging and that actually skips the revocation of the token if it is expired. Refactoring and debugging improvements: * Added a condition to check if the token is expired before running the `Revoke-GitHubAppInstallationAccessToken`. The issue here was that the function would fail if it was expired. * Split the previous compound conditional into three distinct variables: `$isNotGitHubToken`, `$isIATAuthType`, and `$isNotExpired` for clarity and maintainability. * Added `Write-Debug` statements for each condition to facilitate easier troubleshooting and understanding of the script's flow. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 6b2e03e commit 2dff5b7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/functions/public/Auth/Disconnect-GitHubAccount.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@
5959
$contextItem = Resolve-GitHubContext -Context $contextItem
6060

6161
$contextToken = Get-GitHubAccessToken -Context $contextItem -AsPlainText
62-
$isGitHubToken = $contextToken -eq (Get-GitHubToken | ConvertFrom-SecureString -AsPlainText)
63-
if (-not $isGitHubToken -and $contextItem.AuthType -eq 'IAT') {
62+
$isNotGitHubToken = -not ($contextToken -eq (Get-GitHubToken | ConvertFrom-SecureString -AsPlainText))
63+
$isIATAuthType = $contextItem.AuthType -eq 'IAT'
64+
$isNotExpired = $contextItem.TokenExpiresIn -gt 0
65+
Write-Debug "isNotGitHubToken: $isNotGitHubToken"
66+
Write-Debug "isIATAuthType: $isIATAuthType"
67+
Write-Debug "isNotExpired: $isNotExpired"
68+
if ($isNotGitHubToken -and $isIATAuthType -and $isNotExpired) {
6469
Revoke-GitHubAppInstallationAccessToken -Context $contextItem
6570
}
6671

0 commit comments

Comments
 (0)