func (p *Provider) FetchUser(session goth.Session) (_ goth.User, err error) {
	var (
		sess = session.(*Session)
		user = goth.User{
			AccessToken:  sess.AccessToken,
			RefreshToken: sess.RefreshToken,
			Provider:     p.Name(),
			ExpiresAt:    sess.ExpiresAt,
		}
	)

	if user.AccessToken == "" {
		return user, fmt.Errorf("%s cannot get user information without access token", p.name)
	}

	var (
		sig = fmt.Sprintf(
			"app_id=%smethod=users.getInfosecure=1session_key=%s%s",
			p.oauthConfig.ClientID, sess.AccessToken, p.oauthConfig.ClientSecret,
		)
		hasher = md5.New()
	)

	if _, err = io.WriteString(hasher, sig); err != nil {
		return user, err
	}

	var reqURL = fmt.Sprintf(
		"%s?app_id=%s&method=users.getInfo&secure=1&session_key=%s&sig=%x",
		endpointUser, p.oauthConfig.ClientID, sess.AccessToken, hasher.Sum(nil),
	)

	res, err := p.Client().Get(reqURL)
	if err != nil {
		return user, err
	}

	defer res.Body.Close()

	if res.StatusCode != http.StatusOK {
		return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.name, res.StatusCode)
	}

	buf, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return user, err
	}

	var raw []json.RawMessage
	if err = json.Unmarshal(buf, &raw); err != nil {
		return user, err
	}

	if len(raw) == 0 {
		return user, fmt.Errorf("%s cannot get user information", p.name)
	}

	if err = json.Unmarshal(raw[0], &user.RawData); err != nil {
		return user, err
	}

	// extract and ignore all errors
	user.UserID, _ = user.RawData["uid"].(string)
	user.FirstName, _ = user.RawData["first_name"].(string)
	user.LastName, _ = user.RawData["last_name"].(string)
	user.NickName, _ = user.RawData["nick"].(string)
	user.Email, _ = user.RawData["email"].(string)
	user.AvatarURL, _ = user.RawData["pic_big"].(string)

	return user, err
}
// FetchUser will go to MAILRU and access basic information about the user.
FetchUser will go to MAILRU and access basic information about the user.
// FetchUser will go to MAILRU and access basic information about the user .
func (p *Provider) FetchUser(session goth.Session) (_ goth.User, err error) {
	var (
		sess = session.(*Session)
		user = goth.User{
			AccessToken:  sess.AccessToken,
			RefreshToken: sess.RefreshToken,
			Provider:     p.Name(),
			ExpiresAt:    sess.ExpiresAt,
		}
	)
	if user.AccessToken == "" {
		return user, fmt.Errorf("%s cannot get user information without access token", p.name)
	}
	var (
		sig = fmt.Sprintf(
			"app_id=%smethod=users.getInfosecure=1session_key=%s%s",
			p.oauthConfig.ClientID, sess.AccessToken, p.oauthConfig.ClientSecret,
		)
		hasher = md5.New()
	)
	if _, err = io.WriteString(hasher, sig); err != nil {
		return user, err
	}
	var reqURL = fmt.Sprintf(
		"%s?app_id=%s&method=users.getInfo&secure=1&session_key=%s&sig=%x",
		endpointUser, p.oauthConfig.ClientID, sess.AccessToken, hasher.Sum(nil),
	)
	res, err := p.Client().Get(reqURL)
	if err != nil {
		return user, err
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.name, res.StatusCode)
	}
	buf, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return user, err
	}
	var raw []json.RawMessage
	if err = json.Unmarshal(buf, &raw); err != nil {
		return user, err
	}
	if len(raw) == 0 {
		return user, fmt.Errorf("%s cannot get user information", p.name)
	}
	if err = json.Unmarshal(raw[0], &user.RawData); err != nil {
		return user, err
	}
	user.UserID, _ = user.RawData["uid"].(string)
	user.FirstName, _ = user.RawData["first_name"].(string)
	user.LastName, _ = user.RawData["last_name"].(string)
	user.NickName, _ = user.RawData["nick"].(string)
	user.Email, _ = user.RawData["email"].(string)
	user.AvatarURL, _ = user.RawData["pic_big"].(string)
	return user, err
}
func ( p * Provider ) FetchUser ( session goth . Session ) ( _ goth . User , err error ) { var ( sess = session . ( * Session ) user = goth . User { AccessToken : sess . AccessToken , RefreshToken : sess . RefreshToken , Provider : p . Name ( ) , ExpiresAt : sess . ExpiresAt , } ) if user . AccessToken == " " { return user , fmt . Errorf ( " " , p . name ) } var ( sig = fmt . Sprintf ( " " , p . oauthConfig . ClientID , sess . AccessToken , p . oauthConfig . ClientSecret , ) hasher = md5 . New ( ) ) if _ , err = io . WriteString ( hasher , sig ) ; err != nil { return user , err } var reqURL = fmt . Sprintf ( " " , endpointUser , p . oauthConfig . ClientID , sess . AccessToken , hasher . Sum ( nil ) , ) res , err := p . Client ( ) . Get ( reqURL ) if err != nil { return user , err } defer res . Body . Close ( ) if res . StatusCode != http . StatusOK { return user , fmt . Errorf ( " " , p . name , res . StatusCode ) } buf , err := ioutil . ReadAll ( res . Body ) if err != nil { return user , err } var raw [ ] json . RawMessage if err = json . Unmarshal ( buf , & raw ) ; err != nil { return user , err } if len ( raw ) == 0 { return user , fmt . Errorf ( " " , p . name ) } if err = json . Unmarshal ( raw [ 0 ] , & user . RawData ) ; err != nil { return user , err } user . UserID , _ = user . RawData [ " " ] . ( string ) user . FirstName , _ = user . RawData [ " " ] . ( string ) user . LastName , _ = user . RawData [ " " ] . ( string ) user . NickName , _ = user . RawData [ " " ] . ( string ) user . Email , _ = user . RawData [ " " ] . ( string ) user . AvatarURL , _ = user . RawData [ " " ] . ( string ) return user , err }
FetchUser will go to MAILRU and access basic information about the user.
FetchUser will go to MAILRU and access basic information about the user .
// extract and ignore all errors