Go implementation of oAuth2 enabbled HTTP client for interactions with Equinix APIs.
Module implementes Equinix specific client credentials grant type with custom TokenSource
from standard Go oauth2 module.
- Go 1.14+ (to build provider plugin)
-
Import
import "github.com/equinix/oauth2-go"
-
Prepare configuration and get http client
authConfig := oauth2.Config{ ClientID: "myClientId", ClientSecret: "myClientSecret" BaseURL: "https://api.equinix.com"} //*http.Client is returned hc := authConfig.New(context.Background())
-
Use client
*http.Client
created by oAuth2 library will deal with token acquisition, refreshment and population of Authorization headers in subsequent requests.Below example shows how to use oAuth2 client with Resty REST client library
rc := resty.NewWithClient(hc) resp, err := rc.R().Get("https://api.equinix.com/ecx/v3/port/userport") if err != nil { fmt.Println("Error:", err) } else { fmt.Println("Status Code:", resp.StatusCode()) fmt.Println("Body:\n", resp) }