mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-01-07 19:05:39 +00:00
added SAML auth basics and metadata
This commit is contained in:
parent
4a661823e8
commit
933d678e83
@ -8,6 +8,9 @@ import hashlib
|
|||||||
from app import app
|
from app import app
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
|
from onelogin.saml2.auth import OneLogin_Saml2_Auth
|
||||||
|
from onelogin.saml2.utils import OneLogin_Saml2_Utils
|
||||||
|
|
||||||
if 'TIMEOUT' in app.config.keys():
|
if 'TIMEOUT' in app.config.keys():
|
||||||
TIMEOUT = app.config['TIMEOUT']
|
TIMEOUT = app.config['TIMEOUT']
|
||||||
else:
|
else:
|
||||||
@ -159,3 +162,17 @@ def email_to_gravatar_url(email, size=100):
|
|||||||
|
|
||||||
hash_string = hashlib.md5(email).hexdigest()
|
hash_string = hashlib.md5(email).hexdigest()
|
||||||
return "https://s.gravatar.com/avatar/%s?s=%s" % (hash_string, size)
|
return "https://s.gravatar.com/avatar/%s?s=%s" % (hash_string, size)
|
||||||
|
|
||||||
|
def prepare_flask_request(request):
|
||||||
|
url_data = urlparse.urlparse(request.url)
|
||||||
|
return {
|
||||||
|
'http_host': request.host,
|
||||||
|
'server_port': url_data.port,
|
||||||
|
'script_name': request.path,
|
||||||
|
'get_data': request.args.copy(),
|
||||||
|
'post_data': request.form.copy()
|
||||||
|
}
|
||||||
|
|
||||||
|
def init_saml_auth(req):
|
||||||
|
auth = OneLogin_Saml2_Auth(req, custom_base_path=app.config['SAML_PATH'])
|
||||||
|
return auth
|
@ -98,11 +98,16 @@
|
|||||||
<!-- /.col -->
|
<!-- /.col -->
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{% if saml_enabled %}
|
||||||
|
<br>
|
||||||
|
<a href="{{ url_for('saml_login') }}">SAML login</a>
|
||||||
|
{% endif %}
|
||||||
{% if github_enabled %}
|
{% if github_enabled %}
|
||||||
|
<br>
|
||||||
<a href="{{ url_for('github_login') }}">Github oauth login</a>
|
<a href="{{ url_for('github_login') }}">Github oauth login</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br>
|
|
||||||
{% if signup_enabled %}
|
{% if signup_enabled %}
|
||||||
|
<br>
|
||||||
<a href="{{ url_for('register') }}" class="text-center">Create an account </a>
|
<a href="{{ url_for('register') }}" class="text-center">Create an account </a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
25
app/views.py
25
app/views.py
@ -20,6 +20,8 @@ from .models import User, Domain, Record, Server, History, Anonymous, Setting, D
|
|||||||
from app import app, login_manager, github
|
from app import app, login_manager, github
|
||||||
from lib import utils
|
from lib import utils
|
||||||
|
|
||||||
|
from onelogin.saml2.auth import OneLogin_Saml2_Auth
|
||||||
|
from onelogin.saml2.utils import OneLogin_Saml2_Utils
|
||||||
|
|
||||||
jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name
|
jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name
|
||||||
jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name
|
jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name
|
||||||
@ -166,6 +168,27 @@ def github_login():
|
|||||||
return abort(400)
|
return abort(400)
|
||||||
return github.authorize(callback=url_for('authorized', _external=True))
|
return github.authorize(callback=url_for('authorized', _external=True))
|
||||||
|
|
||||||
|
@app.route('/saml/login')
|
||||||
|
def saml_login():
|
||||||
|
if not app.config.get('SAML_ENABLED'):
|
||||||
|
return abort(400)
|
||||||
|
return abort(400)
|
||||||
|
|
||||||
|
@app.route('/saml/metadata/')
|
||||||
|
def saml_metadata():
|
||||||
|
req = utils.prepare_flask_request(request)
|
||||||
|
auth = utils.init_saml_auth(req)
|
||||||
|
settings = auth.get_settings()
|
||||||
|
metadata = settings.get_sp_metadata()
|
||||||
|
errors = settings.validate_metadata(metadata)
|
||||||
|
|
||||||
|
if len(errors) == 0:
|
||||||
|
resp = make_response(metadata, 200)
|
||||||
|
resp.headers['Content-Type'] = 'text/xml'
|
||||||
|
else:
|
||||||
|
resp = make_response(errors.join(', '), 500)
|
||||||
|
return resp
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
@login_manager.unauthorized_handler
|
@login_manager.unauthorized_handler
|
||||||
def login():
|
def login():
|
||||||
@ -175,6 +198,7 @@ def login():
|
|||||||
BASIC_ENABLED = app.config['BASIC_ENABLED']
|
BASIC_ENABLED = app.config['BASIC_ENABLED']
|
||||||
SIGNUP_ENABLED = app.config['SIGNUP_ENABLED']
|
SIGNUP_ENABLED = app.config['SIGNUP_ENABLED']
|
||||||
GITHUB_ENABLE = app.config.get('GITHUB_OAUTH_ENABLE')
|
GITHUB_ENABLE = app.config.get('GITHUB_OAUTH_ENABLE')
|
||||||
|
SAML_ENABLED = app.config.get('SAML_ENABLED')
|
||||||
|
|
||||||
if g.user is not None and current_user.is_authenticated:
|
if g.user is not None and current_user.is_authenticated:
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('dashboard'))
|
||||||
@ -197,6 +221,7 @@ def login():
|
|||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template('login.html',
|
return render_template('login.html',
|
||||||
github_enabled=GITHUB_ENABLE,
|
github_enabled=GITHUB_ENABLE,
|
||||||
|
saml_enabled=SAML_ENABLED,
|
||||||
ldap_enabled=LDAP_ENABLED, login_title=LOGIN_TITLE,
|
ldap_enabled=LDAP_ENABLED, login_title=LOGIN_TITLE,
|
||||||
basic_enabled=BASIC_ENABLED, signup_enabled=SIGNUP_ENABLED)
|
basic_enabled=BASIC_ENABLED, signup_enabled=SIGNUP_ENABLED)
|
||||||
|
|
||||||
|
@ -65,6 +65,9 @@ GITHUB_OAUTH_URL = 'http://127.0.0.1:5000/api/v3/'
|
|||||||
GITHUB_OAUTH_TOKEN = 'http://127.0.0.1:5000/oauth/token'
|
GITHUB_OAUTH_TOKEN = 'http://127.0.0.1:5000/oauth/token'
|
||||||
GITHUB_OAUTH_AUTHORIZE = 'http://127.0.0.1:5000/oauth/authorize'
|
GITHUB_OAUTH_AUTHORIZE = 'http://127.0.0.1:5000/oauth/authorize'
|
||||||
|
|
||||||
|
# SAML Authnetication
|
||||||
|
SAML_ENABLED = True
|
||||||
|
|
||||||
#Default Auth
|
#Default Auth
|
||||||
BASIC_ENABLED = True
|
BASIC_ENABLED = True
|
||||||
SIGNUP_ENABLED = True
|
SIGNUP_ENABLED = True
|
||||||
|
Loading…
Reference in New Issue
Block a user