
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


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

Use new OpenAM token validation endpoint
Use new OpenAM token validation endpoint

  
  from flask import request, redirect
  import requests
  
  cookiename = 'openAMUserCookieName'
  amURL = 'https://openam.example.com/'
- validTokenAPI = amURL + 'openam/identity/istokenvalid?tokenid='
+ 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.get(validTokenAPI + usercookie)
+       amQuery = requests.post(validTokenAPI.format(token=usercookie))
-       if 'boolean=true' in amQuery.text:
+       if amQuery.json()['valid']:
          return f(*args, **kwargs)
      return redirect(loginURL)
    return decorated_function
  
  @app.route('/members_page')
  @session_required
  def members_page():
    pass
  
Use new OpenAM token validation endpoint
## Code Before:

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

## Instruction:
Use new OpenAM token validation endpoint
## Code After:

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
