equinix / oauth2-go

Implementation of Equinix oAuth2 flows in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Build Status Go Report Card GoDoc GitHub


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)
    }
    

About

Implementation of Equinix oAuth2 flows in Go

License:MIT License


Languages

Language:Go 97.4%Language:Makefile 2.6%