Skip to content

Commit 7ea1ff2

Browse files
committed
Empty raw data in steam provider
1 parent 4929279 commit 7ea1ff2

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

providers/steam/steam.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func New(apiKey string, callbackURL string) *Provider {
3030
p := &Provider{
3131
APIKey: apiKey,
3232
CallbackURL: callbackURL,
33+
SummaryURL: apiUserSummaryEndpoint,
3334
providerName: "steam",
3435
}
3536
return p
@@ -39,6 +40,7 @@ func New(apiKey string, callbackURL string) *Provider {
3940
type Provider struct {
4041
APIKey string
4142
CallbackURL string
43+
SummaryURL string
4244
HTTPClient *http.Client
4345
providerName string
4446
}
@@ -114,7 +116,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
114116
return u, fmt.Errorf("%s cannot get user information without SteamID", p.providerName)
115117
}
116118

117-
apiURL := fmt.Sprintf(apiUserSummaryEndpoint, p.APIKey, s.SteamID)
119+
apiURL := fmt.Sprintf(p.SummaryURL, p.APIKey, s.SteamID)
118120
req, err := http.NewRequest("GET", apiURL, nil)
119121
if err != nil {
120122
return u, err
@@ -185,6 +187,17 @@ func buildUserObject(r io.Reader, u goth.User) (goth.User, error) {
185187
u.Location = "No location is provided by the Steam API"
186188
}
187189

190+
// Set raw data
191+
b, err := json.Marshal(&player)
192+
if err != nil {
193+
return u, err
194+
}
195+
196+
err = json.Unmarshal(b, &u.RawData)
197+
if err != nil {
198+
return u, err
199+
}
200+
188201
return u, nil
189202
}
190203

providers/steam/steam_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package steam_test
22

33
import (
4+
"fmt"
5+
"net/http"
6+
"net/http/httptest"
47
"os"
58
"testing"
69

@@ -50,6 +53,61 @@ func Test_SessionFromJSON(t *testing.T) {
5053
a.Equal(s.ResponseNonce, "2016-03-13T16:56:30ZJ8tlKVquwHi9ZSPV4ElU5PY2dmI=")
5154
}
5255

56+
func Test_FetchUser(t *testing.T) {
57+
apiUserSummaryPath := "/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s"
58+
59+
t.Parallel()
60+
a := assert.New(t)
61+
p := provider()
62+
session, err := p.UnmarshalSession(`{"AuthURL":"https://steamcommunity.com/openid/login?openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.realm=%3A%2F%2F&openid.return_to=%2Ffoo","SteamID":"1234567890","CallbackURL":"http://localhost:3030/","ResponseNonce":"2016-03-13T16:56:30ZJ8tlKVquwHi9ZSPV4ElU5PY2dmI="}`)
63+
a.NoError(err)
64+
65+
expectedPath := fmt.Sprintf(apiUserSummaryPath, p.APIKey, "1234567890")
66+
67+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
68+
a.Equal("application/json", r.Header.Get("Accept"))
69+
a.Equal(http.MethodGet, r.Method)
70+
a.Equal(expectedPath, r.URL.RequestURI())
71+
w.Write([]byte(testUserSummaryBody))
72+
}))
73+
74+
p.SummaryURL = ts.URL + apiUserSummaryPath
75+
76+
user, err := p.FetchUser(session)
77+
a.NoError(err)
78+
a.Equal("76561197960435530", user.UserID)
79+
a.Equal("Robin", user.NickName)
80+
a.Equal("Robin Walker", user.Name)
81+
a.Equal("https://avatars.steamstatic.com/81b5478529dce13bf24b55ac42c1af7058aaf7a9_full.jpg", user.AvatarURL)
82+
a.Equal("No email is provided by the Steam API", user.Email)
83+
a.Equal("No description is provided by the Steam API", user.Description)
84+
a.Equal("WA, US", user.Location)
85+
a.Len(user.RawData, 6)
86+
a.Equal("76561197960435530", user.RawData["steamid"])
87+
a.Equal("Robin", user.RawData["personaname"])
88+
a.Equal("Robin Walker", user.RawData["realname"])
89+
a.Equal("https://avatars.steamstatic.com/81b5478529dce13bf24b55ac42c1af7058aaf7a9_full.jpg", user.RawData["avatarfull"])
90+
a.Equal("US", user.RawData["loccountrycode"])
91+
a.Equal("WA", user.RawData["locstatecode"])
92+
}
93+
5394
func provider() *steam.Provider {
5495
return steam.New(os.Getenv("STEAM_KEY"), "/foo")
5596
}
97+
98+
// Extracted from: https://developer.valvesoftware.com/wiki/Steam_Web_API
99+
var testUserSummaryBody = `{
100+
"response": {
101+
"players": [
102+
{
103+
"steamid": "76561197960435530",
104+
"personaname": "Robin",
105+
"realname": "Robin Walker",
106+
"avatarfull": "https://avatars.steamstatic.com/81b5478529dce13bf24b55ac42c1af7058aaf7a9_full.jpg",
107+
"loccountrycode": "US",
108+
"locstatecode": "WA"
109+
}
110+
]
111+
112+
}
113+
}`

0 commit comments

Comments
 (0)