authorization.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package acme
  2. import "net/http"
  3. // FetchAuthorization fetches an authorization from an authorization url provided in an order.
  4. func (c Client) FetchAuthorization(account Account, authURL string) (Authorization, error) {
  5. authResp := Authorization{}
  6. _, err := c.post(authURL, account.URL, account.PrivateKey, "", &authResp, http.StatusOK)
  7. if err != nil {
  8. return authResp, err
  9. }
  10. for i := 0; i < len(authResp.Challenges); i++ {
  11. if authResp.Challenges[i].KeyAuthorization == "" {
  12. authResp.Challenges[i].KeyAuthorization = authResp.Challenges[i].Token + "." + account.Thumbprint
  13. }
  14. }
  15. authResp.ChallengeMap = map[string]Challenge{}
  16. authResp.ChallengeTypes = []string{}
  17. for _, c := range authResp.Challenges {
  18. authResp.ChallengeMap[c.Type] = c
  19. authResp.ChallengeTypes = append(authResp.ChallengeTypes, c.Type)
  20. }
  21. authResp.URL = authURL
  22. return authResp, nil
  23. }
  24. // DeactivateAuthorization deactivate a provided authorization url from an order.
  25. func (c Client) DeactivateAuthorization(account Account, authURL string) (Authorization, error) {
  26. deactivateReq := struct {
  27. Status string `json:"status"`
  28. }{
  29. Status: "deactivated",
  30. }
  31. deactivateResp := Authorization{}
  32. _, err := c.post(authURL, account.URL, account.PrivateKey, deactivateReq, &deactivateResp, http.StatusOK)
  33. return deactivateResp, err
  34. }