@register.inclusion_tag('<STR_LIT>', takes_context=True)<EOL>def disqus_sso(context):
DISQUS_SECRET_KEY = getattr(settings, '<STR_LIT>', None)<EOL>if DISQUS_SECRET_KEY is None:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>DISQUS_PUBLIC_KEY = getattr(settings, '<STR_LIT>', None)<EOL>if DISQUS_PUBLIC_KEY is None:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>user = context['<STR_LIT:user>']<EOL>if user.is_anonymous():<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>data = json.dumps({<EOL>'<STR_LIT:id>': user.id,<EOL>'<STR_LIT:username>': user.username,<EOL>'<STR_LIT:email>': user.email,<EOL>})<EOL>message = base64.b64encode(data.encode('<STR_LIT:utf-8>'))<EOL>timestamp = int(time.time())<EOL>key = DISQUS_SECRET_KEY.encode('<STR_LIT:utf-8>')<EOL>msg = ('<STR_LIT>' % (message, timestamp)).encode('<STR_LIT:utf-8>')<EOL>digestmod = hashlib.sha1<EOL>sig = hmac.HMAC(key, msg, digestmod).hexdigest()<EOL>return  dict(<EOL>message=message,<EOL>timestamp=timestamp,<EOL>sig=sig,<EOL>pub_key=DISQUS_PUBLIC_KEY,<EOL>)<EOL>
Return the HTML/js code to enable DISQUS SSO - so logged in users on
your site can be logged in to disqus seemlessly.