Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions internal/appstore/bag.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (c *Client) bag() (SAPConfig, error) {
return SAPConfig{}, err
}

url := fmt.Sprintf("https://%s%s?guid=%s", initDomain, initPath, g)
bagURL := fmt.Sprintf("https://%s%s?guid=%s", initDomain, initPath, g)

var out bagResult

res, err := c.send(http.MethodGet, url, map[string]string{"Accept": "application/xml"}, nil, nil, formatXML, &out)
res, err := c.send(http.MethodGet, bagURL, map[string]string{"Accept": "application/xml"}, nil, nil, formatXML, &out)
if err != nil {
return SAPConfig{}, fmt.Errorf("bag: %w", err)
}
Expand All @@ -57,6 +57,16 @@ func (c *Client) bag() (SAPConfig, error) {
return SAPConfig{}, fmt.Errorf("bag: %w", err)
}

authEndpoint, err := url.Parse(config.AuthEndpoint)
if err != nil {
return SAPConfig{}, fmt.Errorf("bag: parse authentication endpoint: %w", err)
}

// The bare path returns unusable responses (204/301/HTML); Apple only
// answers the signed authenticate request on the slashed path.
authEndpoint.Path = PrivateAppStoreAPIPathAuth + "/"
config.AuthEndpoint = authEndpoint.String()

return config, nil
}

Expand Down Expand Up @@ -98,7 +108,7 @@ func validateAuthenticationEndpoint(endpoint string) error {
return fmt.Errorf("unsupported authentication endpoint %q", endpoint)
}

if parsed.Path != PrivateAppStoreAPIPathAuth {
if parsed.Path != PrivateAppStoreAPIPathAuth && parsed.Path != PrivateAppStoreAPIPathAuth+"/" {
return fmt.Errorf("unsupported authentication endpoint %q", endpoint)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/appstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func New(cookiesFile string) (*Client, error) {
hc := &http.Client{
Jar: jar,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if req.Referer() == authURL {
if strings.TrimSuffix(req.Referer(), "/") == authURL {
return http.ErrUseLastResponse
}

Expand Down