# Email from Vkontakte social connection

**URL:** <https://community.auth0.com/t/email-from-vkontakte-social-connection/77171>\
**Category:** Get Help\
**Tags:** email, vkontakte, login\
**Created:** [January 27, 2022, 8:21pm UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171 "2022-01-27T20:21:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovannilaperna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giovannilaperna/32/34414_2.png) [@giovannilaperna](https://community.auth0.com/u/giovannilaperna)\
**Post date:** [January 27, 2022, 8:21pm UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171/1 "2022-01-27T20:21:05Z")

</div>

How to get the email on an user accessing my website using Vkontakte social connection?  
I found [this](https://community.auth0.com/t/how-to-get-email-for-vkontakte/8668) and [this](https://community.auth0.com/t/enrich-profile-with-email-for-vkontakte/17800) but still I can get a solution.  
Thank you!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 31, 2022, 8:04pm UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171/3 "2022-01-31T20:04:04Z")

</div>

Hi @giovannilaperna

It looks like the second post you linked shows how to set up a custom social connection which will allow you to request the email.

> [@Enrich profile with Email for Vkontakte](https://community.auth0.com/t/enrich-profile-with-email-for-vkontakte/17800/6):
>
> Rules won’t let you intercept the OAuth2 conversation between Auth0 and vK, so you won’t be able to fix the default VK connection behavior using rules. I believe it should be possible to get the email using a custom social connection though, by: Requesting an email scope In the user profile function, use ctx.email to get the email address from the token response. Have you tried the above?

Were you able to try this method?

---

<div class="post-metadata">

**Author:** ![giovannilaperna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giovannilaperna/32/34414_2.png) [@giovannilaperna](https://community.auth0.com/u/giovannilaperna)\
**Post date:** [January 31, 2022, 10:40pm UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171/4 "2022-01-31T22:40:36Z")

</div>

Hi,

I tried with the following but didn’t work:

```auto
context.accessToken[namespace + 'email'] = context.email;

```

I have the following scopes:

```auto
openid profile email offline_access

```

`context.email` does not exist accordingly to your [documentation](https://auth0.com/docs/customize/rules/context-object).

Any suggest?

This is crucial for me since 1/3 of my users will be using Vkontakte to login.

---

<div class="post-metadata">

**Author:** ![giovannilaperna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giovannilaperna/32/34414_2.png) [@giovannilaperna](https://community.auth0.com/u/giovannilaperna)\
**Post date:** [February 1, 2022, 10:19am UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171/5 "2022-02-01T10:19:58Z")

</div>

I’m now trying to set up a custom social connection but for some reason it fails.  
I contacted vKontakte support for some help because I always get:

```auto
error=invalid_request&error_description=Invalid%20user%20id

```

I don’t know what `invalid user id` means.

---

<div class="post-metadata">

**Author:** ![giovannilaperna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giovannilaperna/32/34414_2.png) [@giovannilaperna](https://community.auth0.com/u/giovannilaperna)\
**Post date:** [February 3, 2022, 11:05am UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171/6 "2022-02-03T11:05:45Z")

</div>

This is solved.

In case someone needs it, the settings and code for Vkontakte custom social connection to get the user email are:

Authorization URL: `https://oauth.vk.com/authorize`  
Token URL : `https://oauth.vk.com/access_token`  
Scope: `email`  
Fetch User Profile Script:

```auto
function fetchUserProfile(accessToken, context, callback){
      const profile = {
        id: context.user_id,
        email: context.email
      };
callback (null, profile);
}

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [February 4, 2022, 9:12pm UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171/7 "2022-02-04T21:12:25Z")

</div>

Thanks for posting your solution!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 19, 2022, 9:13pm UTC](https://community.auth0.com/t/email-from-vkontakte-social-connection/77171/8 "2022-02-19T21:13:16Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
