func (a *BasicAuth) Authenticate(ctx context.Context, c *Client) error {
	// First see if the credentials seem good
	req, err := c.NewRequest(ctx, kivik.MethodGet, "/_session", nil)
	if err != nil {
		return err
	}
	req.SetBasicAuth(a.Username, a.Password)
	res, err := c.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if err = ResponseError(res); err != nil {
		return err
	}
	result := struct {
		Ctx struct {
			Name string `json:"name"`
		} `json:"userCtx"`
	}{}
	if err = json.NewDecoder(res.Body).Decode(&result); err != nil {
		return err
	}
	if result.Ctx.Name != a.Username {
		return errors.New("authentication failed")
	}
	// Everything looks good, lets make this official
	a.transport = c.Transport
	c.Transport = a
	return nil
}
// Authenticate sets HTTP Basic Auth headers for the client.
Authenticate sets HTTP Basic Auth headers for the client.
// Authenticate sets HTTP Basic Auth headers for the client .
func (a *BasicAuth) Authenticate(ctx context.Context, c *Client) error {
	req, err := c.NewRequest(ctx, kivik.MethodGet, "/_session", nil)
	if err != nil {
		return err
	}
	req.SetBasicAuth(a.Username, a.Password)
	res, err := c.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if err = ResponseError(res); err != nil {
		return err
	}
	result := struct {
		Ctx struct {
			Name string `json:"name"`
		} `json:"userCtx"`
	}{}
	if err = json.NewDecoder(res.Body).Decode(&result); err != nil {
		return err
	}
	if result.Ctx.Name != a.Username {
		return errors.New("authentication failed")
	}
	a.transport = c.Transport
	c.Transport = a
	return nil
}
func ( a * BasicAuth ) Authenticate ( ctx context . Context , c * Client ) error { req , err := c . NewRequest ( ctx , kivik . MethodGet , " " , nil ) if err != nil { return err } req . SetBasicAuth ( a . Username , a . Password ) res , err := c . Do ( req ) if err != nil { return err } defer res . Body . Close ( ) if err = ResponseError ( res ) ; err != nil { return err } result := struct { Ctx struct { Name string `json:"name"` } `json:"userCtx"` } { } if err = json . NewDecoder ( res . Body ) . Decode ( & result ) ; err != nil { return err } if result . Ctx . Name != a . Username { return errors . New ( " " ) } a . transport = c . Transport c . Transport = a return nil }
Authenticate sets HTTP Basic Auth headers for the client.
Authenticate sets HTTP Basic Auth headers for the client .
// First see if the credentials seem good // Everything looks good, lets make this official