From e5eab4f828ab0312b1d159608e85c4ce64e039bf Mon Sep 17 00:00:00 2001 From: tomf Date: Sat, 21 Jun 2025 00:49:18 +1000 Subject: [PATCH] MYTHICBEASTS: Performance improvement: Use the OAuth2 client credentials protocol (#3629) --- .../mythicbeasts/mythicbeastsProvider.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/providers/mythicbeasts/mythicbeastsProvider.go b/providers/mythicbeasts/mythicbeastsProvider.go index d811953ed..6980fa265 100644 --- a/providers/mythicbeasts/mythicbeastsProvider.go +++ b/providers/mythicbeasts/mythicbeastsProvider.go @@ -4,6 +4,7 @@ package mythicbeasts import ( + "context" "encoding/json" "errors" "fmt" @@ -15,6 +16,8 @@ import ( "github.com/StackExchange/dnscontrol/v4/pkg/diff2" "github.com/StackExchange/dnscontrol/v4/providers" "github.com/miekg/dns" + "golang.org/x/oauth2" + "golang.org/x/oauth2/clientcredentials" ) // mythicBeastsDefaultNS lists the default nameservers, per https://www.mythic-beasts.com/support/domains/nameservers. @@ -25,8 +28,6 @@ var mythicBeastsDefaultNS = []string{ // mythicBeastsProvider is the handle for this provider. type mythicBeastsProvider struct { - secret string - keyID string client *http.Client } @@ -65,10 +66,16 @@ func newDsp(conf map[string]string, metadata json.RawMessage) (providers.DNSServ if conf["secret"] == "" { return nil, errors.New("missing Mythic Beasts auth secret") } + // Use https://www.mythic-beasts.com/support/api/auth + cfg := clientcredentials.Config{ + ClientID: conf["keyID"], + ClientSecret: conf["secret"], + TokenURL: "https://auth.mythic-beasts.com/login", + Scopes: []string{"client_credentials"}, + AuthStyle: oauth2.AuthStyleInHeader, + } return &mythicBeastsProvider{ - keyID: conf["keyID"], - secret: conf["secret"], - client: &http.Client{}, + client: cfg.Client(context.Background()), }, nil } @@ -77,8 +84,6 @@ func (n *mythicBeastsProvider) httpRequest(method, url string, body io.Reader) ( if err != nil { return nil, err } - // https://www.mythic-beasts.com/support/api/auth - req.SetBasicAuth(n.keyID, n.secret) req.Header.Add("Content-Type", "text/dns") req.Header.Add("Accept", "text/dns") return n.client.Do(req)