12
"xelbot.com/reprogl/container"
15
var vkEndpoint = oauth2.Endpoint{
16
AuthURL: "https://id.vk.com/authorize",
17
TokenURL: "https://id.vk.com/oauth2/auth",
20
type vkResourceOwner struct {
24
type vkUserInfoResponse struct {
25
User vkUser `json:"user"`
29
ID string `json:"user_id"`
30
FirstName string `json:"first_name,omitempty"`
31
LastName string `json:"last_name,omitempty"`
32
Gender int `json:"sex,omitempty"`
33
Email string `json:"email,omitempty"`
34
Avatar string `json:"avatar,omitempty"`
37
func (vkro *vkResourceOwner) GetUserData() (*UserData, error) {
39
data.Set("access_token", vkro.accessToken)
40
data.Set("client_id", container.GetConfig().OAuthVkID)
42
request, err := http.NewRequest(
44
"https://id.vk.com/oauth2/user_info",
45
strings.NewReader(data.Encode()))
50
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
51
request.Header.Set("Accept", "application/json")
53
buf, err := doRequest(request)
59
return nil, errors.New("invalid JSON string")
62
result := vkUserInfoResponse{}
63
err = json.Unmarshal(buf, &result)
69
switch result.User.Gender {
78
userData := &UserData{
80
DisplayName: strings.TrimSpace(result.User.FirstName + " " + result.User.LastName),
81
FirstName: result.User.FirstName,
83
Email: result.User.Email,
84
Avatar: result.User.Avatar,
85
RawData: base64.URLEncoding.EncodeToString(buf),