Skip to content

Commit 03b0a84

Browse files
committed
cfg.Host should be the non-api prefixed host
1 parent d0b1986 commit 03b0a84

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

pkg/http/oauth/oauth_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ func TestAPIHostResolver_AuthorizationServerURL(t *testing.T) {
644644
}{
645645
{
646646
name: "valid host returns authorization server URL",
647-
host: "http://api.github.com",
647+
host: "http://github.com",
648648
expectedURL: "https://github.com/login/oauth",
649649
expectError: false,
650650
},
@@ -657,20 +657,20 @@ func TestAPIHostResolver_AuthorizationServerURL(t *testing.T) {
657657
},
658658
{
659659
name: "host without scheme returns error",
660-
host: "api.github.com",
660+
host: "github.com",
661661
expectedURL: "",
662662
expectError: true,
663663
errorContains: "host must have a scheme",
664664
},
665665
{
666666
name: "GHES host returns correct authorization server URL with subdomain isolation",
667-
host: "https://api.ghe.example.com",
667+
host: "https://ghe.example.com",
668668
expectedURL: "https://ghe.example.com/login/oauth",
669669
expectError: false,
670670
},
671671
{
672672
name: "GHES host returns correct authorization server URL without subdomain isolation",
673-
host: "https://ghe-nosubdomain.example.com/api/v3",
673+
host: "https://ghe-nosubdomain.example.com",
674674
expectedURL: "https://ghe-nosubdomain.example.com/login/oauth",
675675
expectError: false,
676676
},

pkg/utils/api.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ func newGHECHost(hostname string) (APIHost, error) {
125125
return APIHost{}, fmt.Errorf("failed to parse GHEC Raw URL: %w", err)
126126
}
127127

128-
// The authorization server for GHEC is still on the root domain, not the api subdomain
129-
rootHost := strings.TrimPrefix(u.Hostname(), "api.")
130-
authorizationServerURL, err := url.Parse(fmt.Sprintf("https://%s/login/oauth", rootHost))
128+
authorizationServerURL, err := url.Parse(fmt.Sprintf("https://%s/login/oauth", u.Hostname()))
131129
if err != nil {
132130
return APIHost{}, fmt.Errorf("failed to parse GHEC Authorization Server URL: %w", err)
133131
}
@@ -185,16 +183,7 @@ func newGHESHost(hostname string) (APIHost, error) {
185183
return APIHost{}, fmt.Errorf("failed to parse GHES Raw URL: %w", err)
186184
}
187185

188-
// If subdomain isolation is enabled, the hostname will be api.hostname, but the authorization server is still on the root domain at hostname/login/oauth
189-
// If subdomain isolation is not enabled, the hostname is still hostname and the authorization server is at hostname/login/oauth
190-
var rootHost string
191-
if hasSubdomainIsolation {
192-
rootHost = strings.TrimPrefix(u.Hostname(), "api.")
193-
} else {
194-
rootHost = u.Hostname()
195-
}
196-
authorizationServerURL, err := url.Parse(fmt.Sprintf("%s://%s/login/oauth", u.Scheme, rootHost))
197-
186+
authorizationServerURL, err := url.Parse(fmt.Sprintf("%s://%s/login/oauth", u.Scheme, u.Hostname()))
198187
if err != nil {
199188
return APIHost{}, fmt.Errorf("failed to parse GHES Authorization Server URL: %w", err)
200189
}

0 commit comments

Comments
 (0)