client/login.go
4f0d95fa
 package client // import "github.com/docker/docker/client"
7c36a1af
 
 import (
7d62e40f
 	"context"
7c36a1af
 	"encoding/json"
 	"net/url"
 
 	"github.com/docker/docker/api/types"
2732b8a9
 	"github.com/docker/docker/api/types/registry"
7c36a1af
 )
 
 // RegistryLogin authenticates the docker server with a given docker registry.
16233eb0
 // It returns unauthorizedError when the authentication fails.
2732b8a9
 func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) {
7c36a1af
 	resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil)
9c846b2f
 	defer ensureReaderClosed(resp)
7c36a1af
 
 	if err != nil {
2732b8a9
 		return registry.AuthenticateOKBody{}, err
7c36a1af
 	}
 
2732b8a9
 	var response registry.AuthenticateOKBody
7c36a1af
 	err = json.NewDecoder(resp.body).Decode(&response)
 	return response, err
 }