Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dash to underscore replacing leads to duplicate entries in social_auth_by_name_backends #751

Closed
mikek opened this issue Aug 25, 2013 · 5 comments

Comments

@mikek
Copy link

mikek commented Aug 25, 2013

The context_processors.social_auth_by_name_backends adds a new item with dash replaced by undersocre for the backends which the authenticated user has associated with his account.

So after authenticating the social_auth.items|pprint in template reveals duplicate entries like:
[(u'google_oauth2', <UserSocialAuth: bot44cafe - Google-Oauth2>), ('google-oauth2', None), ('facebook', None)].

This makes hard to iterate over them constructing URLs with backend names, etc. Is this replacement a must-have? Could we at least make it consistent by removing items (with None values) replaced in this process? (This does not solve constructing urls though.)

@mikek
Copy link
Author

mikek commented Aug 28, 2013

Even a simple workaround like this would not work if user has not associated account with a dash in backend name. The list will not include the backend with a dash because it is replaced only for associated accounts.

<h3>Connect more accounts (to be able to log in with any of them)</h3>
<ul>
    {% for backend, user_sa in social_auth.items %}
        {% if not user_sa and not '-' in backend %}
            <li><a href="{% url 'socialauth_begin' backend %}">{{ backend }}</a></li>
        {% endif %}
    {% endfor %}
</ul>

@omab omab closed this as completed in 5b9487d Aug 28, 2013
@omab
Copy link
Owner

omab commented Aug 28, 2013

@mikek, I've pushed a fix for this issue, now all backends have - replaced with _ and no more duplicates now. The replacement is done to allow access by attribute in templates, so you can do social_auth.google_oauth2 if needed.

@mikek
Copy link
Author

mikek commented Aug 29, 2013

While we can get disconnect URLs regardless of the backend 'key':

{% for backend, user_sa in social_auth.items %}
    {% if user_sa %}
        {% url 'socialauth_disconnect_individual' user_sa.provider user_sa.id %}
    {% endif %}
{% endfor %}

'socialauth_begin' URLs for backends with dashes are broken now:

{% for backend, user_sa in social_auth.items %}
    {% url 'socialauth_begin' backend %}
{% endfor %}

will produce 'underscored' URLs.

Any other way to iterate over all enabled backends to connect and disconnect accounts?

@omab
Copy link
Owner

omab commented Aug 29, 2013

@mikek, my bad, I've removed the dash replacement with underscore, the dict won't be accessible using dot notation, but seems that nobody is using it like that or an issue would be raised already.

@mikek
Copy link
Author

mikek commented Aug 29, 2013

Thanks, this simple approach should add no controversy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants