Categorygithub.com/equinix/oauth2-go
modulepackage
1.0.0
Repository: https://github.com/equinix/oauth2-go.git
Documentation: pkg.go.dev

# README

Equinix oAuth2 Go client

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.

Requirements

  • Go 1.14+ (to build provider plugin)

Usage

  1. Import

    import "github.com/equinix/oauth2-go"
    
  2. 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())
    
  3. 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)
    }
    

# Structs

Config describes oauth2 client credentials flow.
Error describes oauth2 err.