<commit_before># encoding: utf-8
import base64
import datetime
import json
import jws
import os
import python_jwt as jwt

from google.appengine.api import app_identity
from google.appengine.api import urlfetch

from oauth2client.client import GoogleCredentials

FIREBASE_SCOPES = [
    'https://www.googleapis.com/auth/firebase.database',
    'https://www.googleapis.com/auth/userinfo.email']


def firebase_url():
    return 'https://{}.firebaseio.com'.format(app_identity.get_application_id())


def create_custom_token(uid, is_premium_account):
    service_account_email = app_identity.get_service_account_name()
    payload = {
        'iss': service_account_email,
        'sub': service_account_email,
        'aud': 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
        'uid': uid,
        'claims': {
            'premium_account': is_premium_account
        }
    }
    exp = datetime.timedelta(minutes=60)

    token = jwt.generate_jwt(payload, None, 'RS256', exp)
    header, body, secret = token.split('.')

    # 返ってくるヘッダーは 'alg': 'none' になっているので RS256 に変更
    header = jws.utils.encode({
        'typ': 'JWT',
        'alg': 'RS256'
    }).decode('utf-8')

    # app_identity.sign_blob を使ってサインを作成
    sign = base64.urlsafe_b64encode(app_identity.sign_blob(str(header + '.' + body))[1]).strip('=')

    return header + '.' + body + '.' + sign


TOKEN = None

def get_access_token():
    if os.environ.get('TEST'):
        return 'testtoken'
    global TOKEN
    if TOKEN:
        return TOKEN
    TOKEN = GoogleCredentials\
        .get_application_default()\
        .create_scoped(FIREBASE_SCOPES)\
        .get_access_token()
    return TOKEN


def add_user(data):<commit_msg>Remove token cache<commit_after># encoding: utf-8
import base64
import datetime
import json
import jws
import os
import python_jwt as jwt

from google.appengine.api import app_identity
from google.appengine.api import urlfetch

from oauth2client.client import GoogleCredentials

FIREBASE_SCOPES = [
    'https://www.googleapis.com/auth/firebase.database',
    'https://www.googleapis.com/auth/userinfo.email']


def firebase_url():
    return 'https://{}.firebaseio.com'.format(app_identity.get_application_id())


def create_custom_token(uid, is_premium_account):
    service_account_email = app_identity.get_service_account_name()
    payload = {
        'iss': service_account_email,
        'sub': service_account_email,
        'aud': 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
        'uid': uid,
        'claims': {
            'premium_account': is_premium_account
        }
    }
    exp = datetime.timedelta(minutes=60)

    token = jwt.generate_jwt(payload, None, 'RS256', exp)
    header, body, secret = token.split('.')

    # 返ってくるヘッダーは 'alg': 'none' になっているので RS256 に変更
    header = jws.utils.encode({
        'typ': 'JWT',
        'alg': 'RS256'
    }).decode('utf-8')

    # app_identity.sign_blob を使ってサインを作成
    sign = base64.urlsafe_b64encode(app_identity.sign_blob(str(header + '.' + body))[1]).strip('=')

    return header + '.' + body + '.' + sign


def get_access_token():
    if os.environ.get('TEST'):
        return 'testtoken'
    return GoogleCredentials\
        .get_application_default()\
        .create_scoped(FIREBASE_SCOPES)\
        .get_access_token()


def add_user(data):
{'fraction_non_alphanumeric': 0.12680200058840835, 'fraction_numerical': 0.012944983818770227, 'mean_word_length': 3.358974358974359, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7428086', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1145, 'n_words': 209}