omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

social_core.exceptions.MissingBackend: Missing backend "saml" entry #1096

Closed vsoch closed 6 years ago

vsoch commented 7 years ago

I'm trying to set up SAML following the instructions here:

http://python-social-auth.readthedocs.io/en/latest/installing.html

I'm not having trouble with the SAML part, but just getting the import of load_strategy and load_backend to work. it comes down to this one line, the bug is an ImportError that it cannot find strategy and this makes sense, because strategy is in uppercase:

https://github.com/omab/python-social-auth/blob/master/social/apps/django_app/utils.py#L1

I changed that lowercase s to uppercase, and the site is working again. Now I'm getting this error:

social_core.exceptions.MissingBackend: Missing backend "saml" entry

I'm wondering why following the instructions for the new repo are leading to the installation of this old version? I'm following the installation instructions (is it a mistake to use pip?) and it always winds up that I have this particular file. I would really appreciate help, and maybe a working set of instructions for getting this working? Thank you!

vsoch commented 7 years ago

second bug is fixed, I forgot to add the saml to the settings.py! The first is still an issue (with the capital letter) I think.

ecmascriptguru commented 6 years ago

@vsoch I've got the same issue

social_core.exceptions.MissingBackend: Missing backend "saml" entry

Have you fixed the issue? If yes, would you like to let me know?

vsoch commented 6 years ago

oh hmm, I think it came down to a mismatched version for Python social auth, but I can't remember to be honest. It looks like the version I was using is python-social-auth==0.3.5 (and maybe that resulted in the bug?) but then later I install social-auth-app-django. Here is the applications I was working on, if it helps:

Could it be that your saml metadata isn't being found? Try accessing the URL and see if everything shows up as it should. This looks like a good thread / contender too --> https://github.com/ansible/awx/issues/715#issuecomment-351968394

vsoch commented 6 years ago

And make sure you are using https://github.com/python-social-auth/social-core, I think this was the original version that was replaced by that?

ecmascriptguru commented 6 years ago

Thanks for your help. I've installed the social-auth-core package

social-auth-core==1.7.0

I am working on local - localhost, which can be the reason? For your information, I am following instructions given by here. https://python-social-auth.readthedocs.io/en/latest/backends/saml.html#basic-usage

vsoch commented 6 years ago

Did you install python3-saml?

ecmascriptguru commented 6 years ago

Yes. I did.

python3-saml==1.4.1

vsoch commented 6 years ago

Have you gone to the saml.xml url and confirmed that it's there? Can you post here the fields that you are sending?

ecmascriptguru commented 6 years ago

I didn't create any app to manage saml so just tried to use another app to add the view to download xml. Here it is.

def saml_metadata_view(request, *args, **kwargs):
    complete_url = reverse('books:book_list', args=())
    saml_backend = load_backend(
        load_strategy(request),
        "saml",
        redirect_uri=complete_url,
    )
    metadata, errors = saml_backend.generate_metadata_xml()
    if not errors:
        return HttpResponse(content=metadata, content_type='text/xml')
ecmascriptguru commented 6 years ago

I guess that the url might be the issue so I am creating a temp app to manage the saml

vsoch commented 6 years ago

yes that is logical, the entire saml metadata object needs to be generated from your server via a URL, and you need an app to generate the URL from.

ecmascriptguru commented 6 years ago

@vsoch Unfortunately I couldn't get it working. I hope you would like to give me a few hints. Here are my console logs.

Internal Server Error: /sso/
Traceback (most recent call last):
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_core/backends/utils.py", line 50, in get_backend
    return BACKENDSCACHE[name]
KeyError: 'saml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_core/backends/utils.py", line 55, in get_backend
    return BACKENDSCACHE[name]
KeyError: 'saml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/alexis/workspace/ksw/BWB-Django-Platform/saml/views.py", line 14, in saml_metadata_view
    redirect_uri=complete_url,
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_django/utils.py", line 27, in load_backend
    Backend = get_backend(BACKENDS, name)
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_core/backends/utils.py", line 57, in get_backend
    raise MissingBackend(name)
social_core.exceptions.MissingBackend: Missing backend "saml" entry
[06/Sep/2018 17:08:44] "GET /sso/ HTTP/1.1" 500 96921
/complete/saml/
Internal Server Error: /sso/
Traceback (most recent call last):
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_core/backends/utils.py", line 50, in get_backend
    return BACKENDSCACHE[name]
KeyError: 'saml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_core/backends/utils.py", line 55, in get_backend
    return BACKENDSCACHE[name]
KeyError: 'saml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/alexis/workspace/ksw/BWB-Django-Platform/saml/views.py", line 14, in saml_metadata_view
    redirect_uri=complete_url,
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_django/utils.py", line 27, in load_backend
    Backend = get_backend(BACKENDS, name)
  File "/home/alexis/Environments/bwb/lib/python3.6/site-packages/social_core/backends/utils.py", line 57, in get_backend
    raise MissingBackend(name)
social_core.exceptions.MissingBackend: Missing backend "saml" entry
[06/Sep/2018 17:09:04] "GET /sso/ HTTP/1.1" 500 96921
vsoch commented 6 years ago

Did you register the backend in your settings?

ecmascriptguru commented 6 years ago

Yes, I think so. Here are the configuration.

UTHENTICATION_BACKENDS = (
    # 'social_core.backends.open_id.OpenIdAuth',
    # 'social_core.backends.google.GoogleOpenId',
    # 'social_core.backends.google.GoogleOAuth2',
    # 'social_core.backends.google.GoogleOAuth',
    # 'social_core.backends.twitter.TwitterOAuth',
    # 'social_core.backends.yahoo.YahooOpenId',
    'django.contrib.auth.backends.ModelBackend',
)
vsoch commented 6 years ago

I don't think it's there :)

vsoch commented 6 years ago
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'social_core.backends.saml.SAMLAuth'  # <----
)
ecmascriptguru commented 6 years ago

Thank you so much, @vsoch No one mentioned the configuration - social_core.backends.saml.SAMLAuth. XML download link works now. Thanks again.

vsoch commented 6 years ago

I'm going to close this, since both our issues are resolved. Glad to help!