icanhasclaims/src/claims.py

55 lines
1.3 KiB
Python

#!/usr/bin/env python3
import flask
import json
import urllib.parse
import xml.dom.minidom
from base64 import b64decode
from flask import jsonify
from flask import request
from flask import render_template
import stsparse
app = flask.Flask(__name__)
app.config.update({
'SECRET_KEY': 'super duper secret',
'SAML_METADATA_URL': 'http://somemetadata.com',
})
@app.route('/')
def hello_world():
return "Hello world!"
@app.route('/claims/saml', methods=['POST', 'GET'])
def get_saml_claims():
error = None
if request.method == 'POST':
saml_response = request.form
saml_text = b64decode(urllib.parse.unquote(saml_response['SAMLResponse']), validate=False)
saml_xml = xml.dom.minidom.parseString(saml_text)
attrs = stsparse.parse_saml_attr(saml_xml)
saml_xml = saml_xml.toprettyxml()
return render_template('saml.html', token=saml_xml)
if request.method == 'GET':
return "Dude where's my claims?"
@app.route('/claims/oauth/', methods=['POST', 'GET'])
def get_oauth_claims():
error = None
if request.method == 'POST':
return "Dude where's my claims?"
pass
if request.method == 'GET':
return "Dude where's my claims?"
pass
if __name__ == "__main__":
app.run(ssl_context='adhoc')