pythonflaskoauth-2.0vkrauth

Implementing OAuth2 with Rauth for vk.com


I'm trying to implement Oauth2 authorization using Rauth for vk.com provider and I have the following issue:

As far as I know there is no way to obtain users email address through vk.com api call, but it sends email address with access_token in json format.

My problem is: I do not know how to obtain it from Rauth's "session" object, there is an access_token field but no way to get an email address.

Here is the code:

def callback(self):
    def decode_json(payload):
        return json.loads(payload.decode('utf-8'))
    if 'code' not in request.args:
        return None, None, None
    oauth_session = self.service.get_auth_session(
        data={'code': request.args['code'],
              'grant_type': 'authorization_code',
              'redirect_uri': self.get_callback_url()},
        decoder=decode_json
    )
    me = oauth_session.get("some call to vk.api").json()

Thank you for your help!


Solution

  • Let me explain. Actually, email is returned by Vkontakte along with access token in case it is provided.

    You don't need to use oauth_session.get since it does make a new request, but it is already done, when you got access token. Try to get an object property with oauth_session.email.

    P.S. you can find email using get_raw_access_token.