-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_struct.go
36 lines (31 loc) · 883 Bytes
/
auth_struct.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
35
36
package auth
import "encoding/json"
var providers = map[string]provider{
"google": provider{
userinfoURL: "https://www.googleapis.com/oauth2/v3/userinfo",
respToID: googleRespToUserInfo,
},
"facebook": provider{
// userinfoURL: "https://graph.facebook.com/me?fields=email,first_name,last_name,link,about,id,name,picture,location",
userinfoURL: "https://graph.facebook.com/me?fields=id",
respToID: facebookRespToUserInfo,
},
}
type provider struct {
userinfoURL string
respToID func([]byte) (string, error)
}
func googleRespToUserInfo(respByte []byte) (string, error) {
resp := struct {
ID string `json:"sub"`
}{}
err := json.Unmarshal(respByte, &resp)
return resp.ID, err
}
func facebookRespToUserInfo(respByte []byte) (string, error) {
resp := struct {
ID string `json:"id"`
}{}
err := json.Unmarshal(respByte, &resp)
return resp.ID, err
}