Compare commits

...

3 Commits

Author SHA1 Message Date
Sean McArdle 5beb07a7fe Getting setup for token parsing. 2018-11-06 15:56:42 -08:00
Sean McArdle 8bb9638005 Added requires. 2018-11-06 15:28:29 -08:00
Sean McArdle 028e773e8e Basic template rendering of saml token. 2018-11-06 15:28:21 -08:00
4 changed files with 46 additions and 5 deletions

2
requires.txt Normal file
View File

@ -0,0 +1,2 @@
flask
python3-saml

View File

@ -2,11 +2,16 @@
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({
@ -25,8 +30,11 @@ def get_saml_claims():
error = None
if request.method == 'POST':
saml_response = request.form
saml_xml = b64decode(saml_response['SAMLResponse'])
return saml_xml
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?"
@ -36,12 +44,11 @@ def get_saml_claims():
def get_oauth_claims():
error = None
if request.method == 'POST':
# handle claims token
return "Dude where's my claims?"
pass
if request.method == 'GET':
#
return "Dude where's my claims?"
pass
return render_template('claims.html', error=error)
if __name__ == "__main__":

12
src/stsparse.py Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env python3
import xml.dom.minidom
from functools import singledispatch
@singledispatch
def parse_saml_attr(token):
'''
Takes a string or xml literal as input and returns the saml attributes
as a dictionary claim_name:value.
'''
return None

20
src/templates/saml.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>icanhasclaims</title>
</head>
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
<h1>SAML Token</h1>
<pre><code>
{{ token }}
</code></pre>
</body>
</html>