def handle_google_oauth2_login():
    google = OAuth2Service(
        name='google',
        client_id=current_app.config['GOOGLE_OAUTH_CLIENT_ID'],
        client_secret=current_app.config['GOOGLE_OAUTH_CLIENT_SECRET'],
        base_url='https://google.com',
        authorize_url='https://accounts.google.com/o/oauth2/auth',
        access_token_url='https://www.googleapis.com/oauth2/v3/token',
    )

    code = request.args.get('code')
    if not code:
        url = google.get_authorize_url(**{
            'response_type': 'code',
            'access_type': 'online',
            'scope': 'openid',
            'redirect_uri': url_for('.google_login', _external=True),
            'openid.realm': get_openid_realm(),
        })
        return redirect(url)

    response = json.loads(google.get_raw_access_token(data={
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': url_for('.google_login', _external=True),
    }).content)

    header, payload, secret = str(response['id_token']).split('.')
    payload += '=' * (4 - (len(payload) % 4))
    id_token = json.loads(base64.urlsafe_b64decode(payload))

    user = find_or_create_google_user(
        id_token['sub'], id_token.get('openid_id'))
    logger.info('Google user %s "%s" logged in', user.id, user.name)

    return login_user_and_redirect(user.id)
dataset/ETHPy150Open lalinsky/acoustid-server/acoustid/web/views/user.py/handle_google_oauth2_login/original