Last active
August 29, 2015 14:06
-
-
Save tzmfreedom/09f4f8a26c93cc93bfa2 to your computer and use it in GitHub Desktop.
PolicyAgent side application with Python/Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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