// Authorize performs the initial step in an authorization flow.
// The caller will then need to choose from and perform a set of returned
// challenges using c.Accept in order to successfully complete authorization.
//
// If an authorization has been previously granted, the CA may return
// a valid authorization (Authorization.Status is StatusValid). If so, the caller
// need not fulfill any challenge and can proceed to requesting a certificate.
Authorize performs the initial step in an authorization flow.
The caller will then need to choose from and perform a set of returned
challenges using c.Accept in order to successfully complete authorization.

If an authorization has been previously granted, the CA may return
a valid authorization (Authorization.Status is StatusValid). If so, the caller
need not fulfill any challenge and can proceed to requesting a certificate.
// Authorize performs the initial step in an authorization flow . // The caller will then need to choose from and perform a set of returned // challenges using c . Accept in order to successfully complete authorization . // // If an authorization has been previously granted the CA may return // a valid authorization ( Authorization . Status is StatusValid ) . If so the caller // need not fulfill any challenge and can proceed to requesting a certificate .
func (c *Client) Authorize(ctx context.Context, domain string) (*Authorization, error) {
	if _, err := c.Discover(ctx); err != nil {
		return nil, err
	}
	type authzID struct {
		Type  string `json:"type"`
		Value string `json:"value"`
	}
	req := struct {
		Resource   string  `json:"resource"`
		Identifier authzID `json:"identifier"`
	}{
		Resource:   "new-authz",
		Identifier: authzID{Type: "dns", Value: domain},
	}
	res, err := c.postJWS(ctx, c.Key, c.dir.AuthzURL, req)
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusCreated {
		return nil, responseError(res)
	}
	var v wireAuthz
	if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
		return nil, fmt.Errorf("acme: invalid response: %v", err)
	}
	if v.Status != StatusPending && v.Status != StatusValid {
		return nil, fmt.Errorf("acme: unexpected status: %s", v.Status)
	}
	return v.authorization(res.Header.Get("Location")), nil
}
func ( c * Client ) Authorize ( ctx context . Context , domain string ) ( * Authorization , error ) { if _ , err := c . Discover ( ctx ) ; err != nil { return nil , err } type authzID struct { Type string `json:"type"` Value string `json:"value"` } req := struct { Resource string `json:"resource"` Identifier authzID `json:"identifier"` } { Resource : " " , Identifier : authzID { Type : " " , Value : domain } , } res , err := c . postJWS ( ctx , c . Key , c . dir . AuthzURL , req ) if err != nil { return nil , err } defer res . Body . Close ( ) if res . StatusCode != http . StatusCreated { return nil , responseError ( res ) } var v wireAuthz if err := json . NewDecoder ( res . Body ) . Decode ( & v ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } if v . Status != StatusPending && v . Status != StatusValid { return nil , fmt . Errorf ( " " , v . Status ) } return v . authorization ( res . Header . Get ( " " ) ) , nil }
Authorize performs the initial step in an authorization flow.
Authorize performs the initial step in an authorization flow .