Skip to content

Instantly share code, notes, and snippets.

@hiroaki-yamamoto
Created June 18, 2015 05:25
Show Gist options
  • Save hiroaki-yamamoto/f25676f0958fc42890f1 to your computer and use it in GitHub Desktop.
Save hiroaki-yamamoto/f25676f0958fc42890f1 to your computer and use it in GitHub Desktop.
Disqus SSO remote_auth generation function
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from hashlib import sha1
from hmac import new
from time import time
import base64
import json
def generate_msg(secret, _id, username, email):
json_str = json.dumps({
"id": _id,
"username": username,
"email": email
})
message = base64.b64encode(json_str.encode("utf-8")).decode("utf-8")
cur_time = str(int(time()))
signature = new(
secret.encode("utf-8"),
(" ").join([
message,
cur_time
]).encode("utf-8"),
sha1
).hexdigest()
return (" ").join([message, signature, cur_time])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment