|
73 | 73 | 'DeviceFlow' { |
74 | 74 | Write-Verbose 'Logging in using device flow...' |
75 | 75 | $clientID = $script:Auth.$Mode.ClientID |
76 | | - if ($Mode -ne (Get-GitHubConfig -Name DeviceFlowType -AsPlainText -ea SilentlyContinue)) { |
| 76 | + if ($Mode -ne (Get-GitHubConfig -Name DeviceFlowType -ErrorAction SilentlyContinue)) { |
77 | 77 | Write-Verbose "Using $Mode authentication..." |
78 | 78 | $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope |
79 | 79 | } else { |
80 | | - $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate' -AsPlainText) - (Get-Date) |
| 80 | + $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) |
81 | 81 | $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 |
82 | 82 | $accessTokenValidityText = "$($accessTokenValidity.Hours):$($accessTokenValidity.Minutes):$($accessTokenValidity.Seconds)" |
83 | 83 | if ($accessTokenIsValid) { |
|
91 | 91 | $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) |
92 | 92 | } |
93 | 93 | } else { |
94 | | - $refreshTokenValidity = [datetime](Get-GitHubConfig -Name 'RefreshTokenExpirationDate' -AsPlainText) - (Get-Date) |
| 94 | + $refreshTokenValidity = [datetime](Get-GitHubConfig -Name 'RefreshTokenExpirationDate') - (Get-Date) |
95 | 95 | $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 |
96 | 96 | if ($refreshTokenIsValid) { |
97 | 97 | Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline |
|
140 | 140 | Write-Host '! ' -ForegroundColor DarkYellow -NoNewline |
141 | 141 | Start-Process 'https://github.com/settings/tokens' |
142 | 142 | $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString |
143 | | - $prefix = (ConvertFrom-SecureString $accessTokenValue -AsPlainText) -replace '_.*$', '_*' |
144 | | - if ($prefix -notmatch '^ghp_|^github_pat_') { |
| 143 | + $accessTokenType = (ConvertFrom-SecureString $accessTokenValue -AsPlainText) -replace '_.*$', '_*' |
| 144 | + if ($accessTokenType -notmatch '^ghp_|^github_pat_') { |
145 | 145 | Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline |
146 | | - Write-Host "Unexpected access token format: $prefix" |
| 146 | + Write-Host "Unexpected access token format: $accessTokenType" |
147 | 147 | } |
148 | 148 | $settings = @{ |
149 | 149 | AccessToken = $accessTokenValue |
150 | | - AccessTokenType = $prefix |
| 150 | + AccessTokenType = $accessTokenType |
151 | 151 | ApiBaseUri = 'https://api.github.com' |
152 | 152 | ApiVersion = '2022-11-28' |
153 | 153 | AuthType = $AuthType |
|
0 commit comments