forked from JustaPenguin/assetto-server-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteam.go
34 lines (28 loc) · 879 Bytes
/
steam.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package servermanager
import (
"net/http"
"github.com/sirupsen/logrus"
"github.com/solovev/steam_go"
)
type SteamLoginHandler struct{}
func (slh *SteamLoginHandler) redirectToSteamLogin(backURLFunc func(r *http.Request) string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
opID := steam_go.NewOpenId(r)
switch opID.Mode() {
case "":
http.Redirect(w, r, opID.AuthUrl(), 301)
case "cancel":
logrus.Error("Steam authorization cancelled")
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
default:
steamID, err := opID.ValidateAndGetId()
if err != nil {
logrus.WithError(err).Error("Could not validate steamID")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, backURLFunc(r)+"?steamGUID="+steamID, http.StatusFound)
}
}
}