Skip to content

Instantly share code, notes, and snippets.

@tzmfreedom
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzmfreedom/09f4f8a26c93cc93bfa2 to your computer and use it in GitHub Desktop.
Save tzmfreedom/09f4f8a26c93cc93bfa2 to your computer and use it in GitHub Desktop.
PolicyAgent side application with Python/Flask
# -*- coding: utf-8 -*-
from flask import Flask, request, render_template
import urllib.request
import json
BASE_URL = "http://test.example.com:8080"
#値の検証とuidの取得
def validate(token):
req = urllib.request.Request(
url=BASE_URL + "/openam/json/sessions/" + token + "?_action=validate",
headers={"Content-Type" : "application/json"},
data="".encode()
)
res = urllib.request.urlopen(req)
return json.loads(res.read().decode())
app = Flask(__name__)
@app.route("/")
def index():
#Cookie値を取得
token = request.cookies.get("iPlanetDirectoryPro")
if token == None:
return "none"
#tokenの検証
validate_res = validate(token)
if not validate_res["valid"]:
return "invalid"
#ユーザ属性の取得
req = urllib.request.Request(
url=BASE_URL + "/openam/json/users/" + validate_res["uid"],
headers={"iplanetDirectoryPro" : token}
)
res = urllib.request.urlopen(req)
return res.read().decode()
app.debug = True
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment