forked from limtech/sns
/
oauth.go
39 lines (34 loc) · 1.06 KB
/
oauth.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
37
38
39
package sns
// user gender
const (
OAuthUserGenderFemale int = iota // Female
OAuthUserGenderMale // male
OAuthUserGenderUnknown // unknown
// oauth user platform
OAuthUserPlatformWechat = "wechat" // wechat
OAuthUserPlatformWeibo = "weibo" // weibo
OAuthUserPlatformQQ = "qq" // qq
OAuthUserPlatformGithub = "github" // github
)
// OAuthInterface interface
type OAuthInterface interface {
Authorize(state, callback string) string
AccessToken(code, state, callback string) (OAuthAccessToken, error)
Userinfo(accessToken, openID string) (OAuthUserinfo, error)
}
// OAuthAccessToken access token
type OAuthAccessToken struct {
AccessToken string `json:"access_token"`
OpenID string `json:"openid"`
UnionID string `json:"unionid"`
}
// OAuthUserinfo common struct
type OAuthUserinfo struct {
Platform string `json:"platform"`
Name string `json:"name"`
OpenID string `json:"openid"`
UnionID string `json:"unionid"`
Avatar string `json:"avatar"`
Gender int `json:"gender"`
Detail string `json:"-"`
}