Skip to content

Commit

Permalink
Added support for local metadata file.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevPo committed Sep 20, 2018
1 parent 90a2409 commit df1ab60
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Contributors
- `Tonymke <https://github.com/tonymke/>`_
- `pintor <https://github.com/pintor>`_
- `BaconAndEggs <https://github.com/BaconAndEggs>`_
- `kevPo <https://github.com/kevPo>`_
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ How to use?
.. code-block:: python
SAML2_AUTH = {
# Required setting
# Metadata is required, choose either remote url or local file path
'METADATA_AUTO_CONF_URL': '[The auto(dynamic) metadata configuration URL of SAML2]',
'METADATA_LOCAL_FILE_PATH': '[The metadata configuration file path]',
# Optional settings below
'DEFAULT_NEXT_URL': '/admin', # Custom target redirect URL after the user get logged in. Default to /admin if not set. This setting will be overwritten if you have parameter ?next= specificed in the login URL.
Expand Down Expand Up @@ -158,6 +159,8 @@ Explanation

**METADATA_AUTO_CONF_URL** Auto SAML2 metadata configuration URL

**METADATA_LOCAL_FILE_PATH** SAML2 metadata configuration file path

**NEW_USER_PROFILE** Default settings for newly created users

**ATTRIBUTES_MAP** Mapping of Django user attributes to SAML2 user attributes
Expand Down
24 changes: 17 additions & 7 deletions django_saml2_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,27 @@ def get_reverse(objs):
raise Exception('We got a URL reverse issue: %s. This is a known issue but please still submit a ticket at https://github.com/fangli/django-saml2-auth/issues/new' % str(objs))


def _get_saml_client(domain):
acs_url = domain + get_reverse([acs, 'acs', 'django_saml2_auth:acs'])

saml_settings = {
'metadata': {
def _get_metadata():
if 'METADATA_LOCAL_FILE_PATH' in settings.SAML2_AUTH:
return {
'local': [settings.SAML2_AUTH['METADATA_LOCAL_FILE_PATH']]
}
else:
return {
'remote': [
{
"url": settings.SAML2_AUTH['METADATA_AUTO_CONF_URL'],
},
],
},
]
}


def _get_saml_client(domain):
acs_url = domain + get_reverse([acs, 'acs', 'django_saml2_auth:acs'])
metadata = _get_metadata()

saml_settings = {
'metadata': metadata,
'service': {
'sp': {
'endpoints': {
Expand Down

0 comments on commit df1ab60

Please sign in to comment.