Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed authorization against Cesenta Docker registry authentication #3795

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion remotes/docker/authorizer.go
Expand Up @@ -323,6 +323,7 @@ type tokenOptions struct {
}

type postTokenResponse struct {
Token string `json:"token"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
Expand Down Expand Up @@ -350,6 +351,9 @@ func (ah *authHandler) fetchTokenWithOAuth(ctx context.Context, to tokenOptions)
if err != nil {
return "", err
}
if to.username != "" {
req.SetBasicAuth(to.username, to.secret)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
if ah.header != nil {
for k, v := range ah.header {
Expand Down Expand Up @@ -385,7 +389,18 @@ func (ah *authHandler) fetchTokenWithOAuth(ctx context.Context, to tokenOptions)
return "", fmt.Errorf("unable to decode token response: %s", err)
}

return tr.AccessToken, nil
// `access_token` is equivalent to `token` and if both are specified
// the choice is undefined. Canonicalize `access_token` by sticking
// things in `token`.
if tr.AccessToken != "" {
tr.Token = tr.AccessToken
}

if tr.Token == "" {
return "", ErrNoToken
}

return tr.Token, nil
}

type getTokenResponse struct {
Expand Down