From 2b300a6228821def85cb7e6f405316e5f49ee21a Mon Sep 17 00:00:00 2001 From: Ruin Date: Mon, 10 Dec 2018 04:56:08 -0800 Subject: [PATCH 1/2] updated battle.net provioder to use the new oauth serivces --- providers/battlenet/battlenet.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/providers/battlenet/battlenet.go b/providers/battlenet/battlenet.go index 491a643ba..65ac9cf13 100644 --- a/providers/battlenet/battlenet.go +++ b/providers/battlenet/battlenet.go @@ -7,9 +7,9 @@ import ( "encoding/json" "io/ioutil" "net/http" - "net/url" "fmt" + "github.com/markbates/goth" "golang.org/x/oauth2" ) @@ -17,7 +17,7 @@ import ( const ( authURL string = "https://us.battle.net/oauth/authorize" tokenURL string = "https://us.battle.net/oauth/token" - endpointUser string = "https://us.api.battle.net/account/user" + endpointUser string = "https://us.battle.net/oauth/userinfo" ) // Provider is the implementation of `goth.Provider` for accessing Battle.net. @@ -84,7 +84,11 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { } // Get the userID, battlenet needs userID in order to get user profile info - response, err := p.Client().Get(endpointUser + "?access_token=" + url.QueryEscape(sess.AccessToken)) + c := p.Client() + req, _ := http.NewRequest("GET", endpointUser, nil) + req.Header.Add("Authorization", "Bearer "+sess.AccessToken) + + response, err := c.Do(req) if err != nil { if response != nil { response.Body.Close() From 61ca2979b546515dc702ac715daadd1ef6767174 Mon Sep 17 00:00:00 2001 From: Ruin Date: Mon, 10 Dec 2018 11:33:45 -0800 Subject: [PATCH 2/2] added error handling --- providers/battlenet/battlenet.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/providers/battlenet/battlenet.go b/providers/battlenet/battlenet.go index 65ac9cf13..e1270bf35 100644 --- a/providers/battlenet/battlenet.go +++ b/providers/battlenet/battlenet.go @@ -85,7 +85,11 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { // Get the userID, battlenet needs userID in order to get user profile info c := p.Client() - req, _ := http.NewRequest("GET", endpointUser, nil) + req, err := http.NewRequest("GET", endpointUser, nil) + if err != nil { + return user, err + } + req.Header.Add("Authorization", "Bearer "+sess.AccessToken) response, err := c.Do(req)