Created
June 15, 2015 16:12
-
-
Save agtorre/edd6c01e317afb0d03a1 to your computer and use it in GitHub Desktop.
Example usage of https://godoc.org/golang.org/x/oauth2/clientcredentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
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
https://gist.github.com/sergeyklay/9f51bcd6905788382b5deb790c68eac1