OAuth 2 Community Implementation Examples

Members of the developer community have requested examples for OAuth implementations in different languages. We’ve created a few examples which can be found here, but in recognition of the talented developers in our community, we wanted to invite you to share your own!

Feel free to contribute your own examples of OAuth Client Credentials flow in this thread!

Golang example for using the golang oauth client for the Client Credential flow.

I felt like most other examples weren’t using the oauth2 library, and this makes it easy, plus it gives you auto-refresh of the oauth credential if it expires.

package main

import (
	"context"
	"io/ioutil"
	"log"

	"golang.org/x/oauth2/clientcredentials"
)

func main() {
	// Setup oauth2 config
	conf := &clientcredentials.Config{
		ClientID:     "client_id_here",
		ClientSecret: "client_secret_here",
		TokenURL:     "https://us.battle.net/oauth/token",
	}

	// Get a HTTP client
	client := conf.Client(context.Background())

	// Use the client, to get a WoW boss, and print the result
	resp, err := client.Get("https://us.api.blizzard.com/wow/boss/24723")
	if err != nil {
		log.Fatal(err)
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("response: ", string(body))
}
1 Like