Skip to content

Instantly share code, notes, and snippets.

@agtorre
Created June 15, 2015 16:12
Show Gist options
  • Save agtorre/edd6c01e317afb0d03a1 to your computer and use it in GitHub Desktop.
Save agtorre/edd6c01e317afb0d03a1 to your computer and use it in GitHub Desktop.
package main
import (
"golang.org/x/oauth2/clientcredentials"
"golang.org/x/net/context"
)
func main(){
// this should match whatever service has given you
// client credential access
config := clientcredentials.Config{
ClientID: "id",
ClientSecret: "secret"
TokenURL: "https://www.fakeoauthprovider.com/token",
Scioes: []string{"some_scope_value"}
}
// you can modify the client (for example ignoring bad certs or otherwise)
// by modifying the context
client, err := config.Client(context.Background())
if err != nil{
panic(err)
}
// the client will update its token if it's expired
resp, err := client.Get("https://www.fakeapiprovider.com/endpoint")
if err != nil{
panic(err)
}
// do something with resp
}
@intel352
Copy link

@agtorre, typo on line 16, should be Scopes I believe.

@ernsheong
Copy link

Is there a way to make this work with self-signed certs for local testing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment