<commit_before># -*- coding:utf-8 -*-

from flask import request, redirect
import requests

cookiename = 'openAMUserCookieName'
amURL = 'https://openam.example.com/'
validTokenAPI = amURL + 'openam/identity/istokenvalid?tokenid='
loginURL = amURL + 'openam/UI/Login'

def session_required(f):
  @wraps(f)
  def decorated_function(*args, **kwargs):
    usercookie = request.cookies.get(cookiename)
    if usercookie:
      amQuery = requests.get(validTokenAPI + usercookie)
      if 'boolean=true' in amQuery.text:
        return f(*args, **kwargs)
    return redirect(loginURL)
  return decorated_function

@app.route('/members_page')
@session_required
def members_page():
  pass
<commit_msg>Use new OpenAM token validation endpoint<commit_after># -*- coding:utf-8 -*-

from flask import request, redirect
import requests

cookiename = 'openAMUserCookieName'
amURL = 'https://openam.example.com/'
validTokenAPI = amURL + 'openam/json/sessions/{token}?_action=validate'
loginURL = amURL + 'openam/UI/Login'

def session_required(f):
  @wraps(f)
  def decorated_function(*args, **kwargs):
    usercookie = request.cookies.get(cookiename)
    if usercookie:
      amQuery = requests.post(validTokenAPI.format(token=usercookie))
      if amQuery.json()['valid']:
        return f(*args, **kwargs)
    return redirect(loginURL)
  return decorated_function

@app.route('/members_page')
@session_required
def members_page():
  pass

{'fraction_non_alphanumeric': 0.12842105263157894, 'fraction_numerical': 0.0014035087719298245, 'mean_word_length': 4.704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '6828759', 'n_tokens_mistral': 456, 'n_tokens_neox': 461, 'n_words': 98}