(ctx context.Context, challenge challenge, scopes []authScope)
| 765 | } |
| 766 | |
| 767 | func (c *dockerClient) getBearerTokenOAuth2(ctx context.Context, challenge challenge, |
| 768 | scopes []authScope) (*bearerToken, error) { |
| 769 | realm, ok := challenge.Parameters["realm"] |
| 770 | if !ok { |
| 771 | return nil, errors.New("missing realm in bearer auth challenge") |
| 772 | } |
| 773 | |
| 774 | authReq, err := http.NewRequestWithContext(ctx, http.MethodPost, realm, nil) |
| 775 | if err != nil { |
| 776 | return nil, err |
| 777 | } |
| 778 | |
| 779 | // Make the form data required against the oauth2 authentication |
| 780 | // More details here: https://docs.docker.com/registry/spec/auth/oauth/ |
| 781 | params := authReq.URL.Query() |
| 782 | if service, ok := challenge.Parameters["service"]; ok && service != "" { |
| 783 | params.Add("service", service) |
| 784 | } |
| 785 | |
| 786 | for _, scope := range scopes { |
| 787 | if scope.resourceType != "" && scope.remoteName != "" && scope.actions != "" { |
| 788 | params.Add("scope", fmt.Sprintf("%s:%s:%s", scope.resourceType, scope.remoteName, scope.actions)) |
| 789 | } |
| 790 | } |
| 791 | params.Add("grant_type", "refresh_token") |
| 792 | params.Add("refresh_token", c.auth.IdentityToken) |
| 793 | params.Add("client_id", "containers/image") |
| 794 | |
| 795 | authReq.Body = io.NopCloser(strings.NewReader(params.Encode())) |
| 796 | authReq.Header.Add("User-Agent", c.userAgent) |
| 797 | authReq.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
| 798 | logrus.Debugf("%s %s", authReq.Method, authReq.URL.Redacted()) |
| 799 | res, err := c.client.Do(authReq) |
| 800 | if err != nil { |
| 801 | return nil, err |
| 802 | } |
| 803 | defer res.Body.Close() |
| 804 | if err := httpResponseToError(res, "Trying to obtain access token"); err != nil { |
| 805 | return nil, err |
| 806 | } |
| 807 | |
| 808 | return newBearerTokenFromHTTPResponseBody(res) |
| 809 | } |
| 810 | |
| 811 | func (c *dockerClient) getBearerToken(ctx context.Context, challenge challenge, |
| 812 | scopes []authScope) (*bearerToken, error) { |
no test coverage detected