Comments (1)
Python3:
import base64
import hashlib
import hmac
import json
import time
DISQUS_SECRET_KEY = '123456'
DISQUS_PUBLIC_KEY = 'abcdef'
def get_disqus_sso():
# create a JSON packet of our data attributes
data = json.dumps({
'id': user['id'],
'username': user['username'],
'email': user['email'],
})
# encode the data to base64
message = base64.b64encode(data.encode('utf-8')).decode()
# generate a timestamp for signing the message
timestamp = int(time.time())
key = DISQUS_SECRET_KEY.encode('utf-8')
msg = ('%s %s' % (message, timestamp)).encode('utf-8')
digestmod = hashlib.sha1
# generate our hmac signature
sig = hmac.HMAC(key, msg, digestmod).hexdigest()
# return a script tag to insert the sso message
return """<script type="text/javascript">
var disqus_config = function() {
this.page.remote_auth_s3 = "%(message)s %(sig)s %(timestamp)s";
this.page.api_key = "%(pub_key)s";
}
</script>""" % dict(
message=message,
timestamp=timestamp,
sig=sig,
pub_key=DISQUS_PUBLIC_KEY,
)
from disqus-api-recipes.
Related Issues (17)
- Disqus oAuth on Flask : CSRF verification failed error
- ruby / sso.rb
- Disabled SSL in PHP samples
- Websocket connection to xxx failed on Chromium
- disqus_config
- Integrating disqus in a mobile app HOT 46
- "Comment reply created" notification
- Google OAuth going away in April 2017 for web views HOT 1
- disqus_reset.html unused vars HOT 1
- I am struggling to work out how to include Disqus comments in an ionic 3/Cordova app
- Is there a way to create moderators via SSO
- 0x94f16cbef0921696d5611a74e30a237fd46444112f3c24a3dd8c0d49cd5ec22e5ae718827dc6152119be51573ad5e694 HOT 1
- Location of recipes needs snippets prefix to path in README.markdown (but I found it eventually) HOT 1
- Is it possible to access all comments via the PHP API in order to provide them to an internal search engine? HOT 1
- Disqus resize on orientation change? HOT 9
- No license/conditions of reuse
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from disqus-api-recipes.