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

fix for disqus_sso tag #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion disqus/templates/disqus/disqus_sso.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
var disqus_config = function() {
this.page.remote_auth_s3 = "{{ message }} {{ sig }} {{ timestamp }}";
this.page.api_key = "{{ pub_key }}";

// This adds the custom login/logout functionality
this.sso = {
{% if SSO_NAME %}name: "{{ SSO_NAME }}",{% endif %}
{% if SSO_BUTTON %}button: "{{ SSO_BUTTON }}",{% endif %}
{% if SSO_ICON %}icon: "{{ SSO_ICON }}",{% endif %}
{% if SSO_URL %}url: "{{ SSO_URL }}",{% endif %}
{% if SSO_LOGOUT %}logout: "{{ SSO_LOGOUT }}",{% endif %}
{% if SSO_WIDTH %}width: "{{ SSO_WIDTH }}",{% endif %}
{% if SSO_HEIGHT %}height: "{{ SSO_HEIGHT }}",{% endif %}
};
}
</script>
</script>
47 changes: 32 additions & 15 deletions disqus/templatetags/disqus_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,30 @@ def disqus_sso(context):
if DISQUS_PUBLIC_KEY is None:
return "<p>You need to set DISQUS_PUBLIC_KEY before you can use SSO</p>"

user = context['user']
SSO_AVATAR = getattr(settings, 'SSO_AVATAR', None)
SSO_NAME = getattr(settings, 'SSO_NAME', None)
SSO_BUTTON = getattr(settings, 'SSO_BUTTON', None)
SSO_ICON = getattr(settings, 'SSO_ICON', None)
SSO_URL = getattr(settings, 'SSO_URL', None)
SSO_LOGOUT = getattr(settings, 'SSO_LOGOUT', None)
SSO_WIDTH = getattr(settings, 'SSO_WIDTH', None)
SSO_HEIGHT = getattr(settings, 'SSO_HEIGHT', None)

if user.is_anonymous():
return ""
user = context['user']

# create a JSON packet of our data attributes
data = json.dumps({
'id': user.id,
'username': user.username,
'email': user.email,
})
if user.is_authenticated():
# create a JSON packet of our data attributes
data = json.dumps({
'id': user.id,
'username': user.username,
'email': user.email,
'avatar': eval(SSO_AVATAR),
})

# encode the data to base64
message = base64.b64encode(data.encode('utf-8'))
# encode the data to base64
message = base64.b64encode(data.encode('utf-8')).decode()
else:
message = None

# generate a timestamp for signing the message
timestamp = int(time.time())
Expand All @@ -119,10 +129,17 @@ def disqus_sso(context):
sig = hmac.HMAC(key, msg, digestmod).hexdigest()

return dict(
message=message,
timestamp=timestamp,
sig=sig,
pub_key=DISQUS_PUBLIC_KEY,
message = message,
timestamp = timestamp,
sig = sig,
pub_key = DISQUS_PUBLIC_KEY,
SSO_NAME = SSO_NAME,
SSO_BUTTON = SSO_BUTTON,
SSO_ICON = SSO_ICON,
SSO_URL = SSO_URL,
SSO_LOGOUT = SSO_LOGOUT,
SSO_WIDTH = SSO_WIDTH,
SSO_HEIGHT = SSO_HEIGHT,
)

@register.inclusion_tag('disqus/num_replies.html', takes_context=True)
Expand Down