Authorization on the site occurs through the app.
<a class="nav-link" href="{{ url_for('auth.vk_login') }}">Войти через ВК</a> Forward to receive code
@auth.route('/redirect_to_vk_login', methods=['POST', 'GET']) def vk_login(): vk_info = get_vk() url = 'https://oauth.vk.com/authorize?client_id=%s&display=popup&redirect_uri=%s&response_type=code&v=5".73' % ( vk_info['id'], vk_info['url']) return redirect(url) Token acquisition and redirection function:
@auth.route('/login') def login(): if request.args.get('code') is None: return abort(501) ... получаю токен ... записываю в бд # Get information about the user data = {'user_id': response.json().get('user_id')} url = 'https://api.vk.com/method/users.get' response = requests.post(url, params=data).json()['response'][0] information_about_user = { 'logged_in': True, 'user_id': response['uid'], 'first_name': response['first_name'], 'last_name': response['last_name'] } session.update(information_about_user) # Как сделать переход на прошлую страницу после авторизации? return redirect(...)