microsoft / PowerShellForGitHub

Microsoft PowerShell wrapper for GitHub API
Other
582 stars 184 forks source link

Get-GitHubUser fails #399

Closed Liturgist closed 1 year ago

Liturgist commented 1 year ago

A description of your problem or question

I seem to have regressed. I thought this was working.

Test-GitHubAuthenticationConfigured returns True, but Get-GitHubUser fails. The github.com/enterprises/myco web interface shows that the_user can login. I cannot give out company information, so I have created variables to make this easier to repro.

Steps to reproduce the issue

$CompanyName = 'theco'
$PatFileName = '~/github-theuser-all.txt'
$UserName = 'theuser'

Clear-GitHubAuthentication
$secureString = ((Get-Content -Path $PatFileName) | ConvertTo-SecureString -AsPlainText -Force)
$cred = New-Object System.Management.Automation.PSCredential $Env:USERNAME, $secureString
Set-GitHubAuthentication -Credential $cred
$secureString = $null
$cred = $null
Test-GitHubAuthenticationConfigured
Reset-GitHubConfiguration
Get-GitHubConfiguration -Name 'ApiHostname'
Set-GitHubConfiguration -ApiHostName "github.com/enterprises/$CompanyName"
Get-GitHubConfiguration -Name 'ApiHostname'
Get-GitHubUser -UserName $UserName -Verbose

Verbose logs showing the problem

When run as a script, the following is produced. 'theuser' can login through the web interface successfully.

True
github.com
github.com/enterprises/theco
VERBOSE: [0.16.1] Executing: Get-GitHubUser -UserName "theuser" -Verbose:$true
VERBOSE: Getting user theuser
VERBOSE: Accessing [Get] https://github.com/enterprises/theco/api/v3/users/theuser [Timeout = 0)]
VERBOSE: HTTP/1.1 GET with 0-byte payload
VERBOSE: received -byte response of content type text/plain
VERBOSE: [0.16.1] Executing: Set-TelemetryException -ErrorBucket "Get-GitHubUser"
VERBOSE: Sending telemetry event data to https://dc.services.visualstudio.com/v2/track [Timeout = 0)]
VERBOSE: HTTP/1.1 POST with 1379-byte payload
VERBOSE: received 49-byte response of content type application/json
Invoke-WebRequest: C:\Users\theuser\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1:313
Line |
 313 |              $result = Invoke-WebRequest @params
     |                        ~~~~~~~~~~~~~~~~~~~~~~~~~
     | Not Found

Suggested solution to the issue

N/A.

Operating System

PS C:\>         Get-ComputerInfo -Property @(
>>             'OsName',
>>             'OsOperatingSystemSKU',
>>             'OSArchitecture',
>>             'WindowsVersion',
>>             'WindowsBuildLabEx',
>>             'OsLanguage',
>>             'OsMuiLanguages')

OsName               : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell Version

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module Version

PS C:\>         @(
>>             "Running: $((Get-Module -Name PowerShellForGitHub) | Select-Object -ExpandProperty Version)",
>>             "Installed: $((Get-Module -Name PowerShellForGitHub -ListAvailable) | Select-Object -ExpandProperty Version)"
>>         ) -join [Environment]::NewLine
>>
Running: 0.16.1
Installed: 0.16.1
HowardWolosky commented 1 year ago

Test-GitHubAuthenticationConfigured just checks to see if you've configured an AccessToken. It doesn't do anything to check if the AccessToken is valid...you find that out when you use a function.

Ultimately, I think this comes down to you setting the correct ApiHostname, my best guess is that github.com/enterprises/$CompanyName is simply not the right value. You should check your configuration/documentation and determine what the appropriate REST endpoint is.

Liturgist commented 1 year ago

github.com/enterprises/$CompanyName is exactly the same string used when I login to GitHub through a web browser.

The output, including verbose output, does not provide a clue as to what the problem is. What am I missing?

Liturgist commented 1 year ago

The answer appears to be that for Enterprise Cloud users, the ApiHostName should not be changed from github.com.

An org URL is https://github.com/OrgName. This would imply that ALL organization names across ALL GitHub Enterprise Cloud customers must be unique. If not, then how are they distinguished.

If Acme Corp creates a SALES organization, then Widget Corp would not be able to create a SALES organization. Is that really true?