<commit_before>from flask import Blueprint, redirect, url_for, session, request, jsonify
from flask_oauthlib.client import OAuth
import requests

google_oauth_provider = Blueprint('google_oauth_provider', __name__)


from app import app
from . import user_access
from config.config import BaseConfig

oauth = OAuth(app.app)

google = oauth.remote_app(
    'google',
    consumer_key= BaseConfig.GOOGLE_ID,
    consumer_secret= BaseConfig.GOOGLE_SECRET,
    request_token_params={
        'scope': 'email'
    },
    base_url='https://www.googleapis.com/oauth2/v1/',
    request_token_url=None,
    access_token_method='POST',
    access_token_url='https://accounts.google.com/o/oauth2/token',
    authorize_url='https://accounts.google.com/o/oauth2/auth',
)
verifyURL = 'https://www.googleapis.com/oauth2/v3/tokeninfo'


@google_oauth_provider.route('/google/verify', methods=['POST'])
def verifyUserId():
    print(request)
    token = request.get_json().get('tokenId')
    print(token)
    payload = {'id_token': token}
    req = requests.get(verifyURL, payload)
    data = req.json()
    print(data)
    id = data['sub']
    print(data)
    user = user_access.get_user_secret('google', id)
    if user:
        # update user details
        print('update')
        user_access.update_user('google', user.secret, data)
        print('user ', user.id, 'secret ', user.secret)
    else:
        print('create')
        user = user_access.create_user('google', data, payload['id_token'])
    return jsonify(userId=user.id, secret=user.secret)


@google_oauth_provider.route('/google/login')
def login():<commit_msg>userId --> user.id<commit_after>from flask import Blueprint, redirect, url_for, session, request, jsonify
from flask_oauthlib.client import OAuth
import requests

google_oauth_provider = Blueprint('google_oauth_provider', __name__)


from app import app
from . import user_access
from config.config import BaseConfig

oauth = OAuth(app.app)

google = oauth.remote_app(
    'google',
    consumer_key= BaseConfig.GOOGLE_ID,
    consumer_secret= BaseConfig.GOOGLE_SECRET,
    request_token_params={
        'scope': 'email'
    },
    base_url='https://www.googleapis.com/oauth2/v1/',
    request_token_url=None,
    access_token_method='POST',
    access_token_url='https://accounts.google.com/o/oauth2/token',
    authorize_url='https://accounts.google.com/o/oauth2/auth',
)
verifyURL = 'https://www.googleapis.com/oauth2/v3/tokeninfo'


@google_oauth_provider.route('/google/verify', methods=['POST'])
def verifyUserId():
    print(request)
    token = request.get_json().get('tokenId')
    print(token)
    payload = {'id_token': token}
    req = requests.get(verifyURL, payload)
    data = req.json()
    print(data)
    id = data['sub']
    print(data)
    user = user_access.get_user_secret('google', id)
    if user:
        # update user details
        print('update')
        user_access.update_user('google', user.secret, data)
        print('user ', user.id, 'secret ', user.secret)
    else:
        print('create')
        user = user_access.create_user('google', data, payload['id_token'])
    return jsonify(id=user.id, secret=user.secret)


@google_oauth_provider.route('/google/login')
def login():
{'fraction_non_alphanumeric': 0.13564571074636111, 'fraction_numerical': 0.0037163208423660575, 'mean_word_length': 3.9692307692307693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1425087', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1054, 'n_words': 192}