单点登录

单点登录的方式与smartchart进行对接嵌入 #

'/echart/smart_login?id=xxx&stamp=xxx&token=xxx&url=/'
'''
参数说明:
id: 用户名(在smartchart平台中管理)
stamp: 时间戳(1970年1月1日到生成时间的毫秒数)
token: 采用sha1加密, token=SHA1(链接秘钥+stamp+id)
       请在安装smartchart的这台机器上设定环境变量SMART_KEY = 链接秘钥
url: 登录成功后跳转链接
'''

Python后台样列: #

import time
import hashlib
import os

"""
参数说明:
id: 用户名(在smartchart平台中管理)
stamp: 时间戳(1970年1月1日到生成时间的毫秒数)
token: 采用sha1加密, token=SHA1(链接秘钥+stamp+id)
url: 登录成功后跳转链接
"""

SMART_CHART_URL = 'http://127.0.0.1:8000'
LOGIN_URL = SMART_CHART_URL + '/echart/smart_login?id={id}&stamp={stamp}&token={token}&url={url}'
SMART_KEY = 链接秘钥


def get_smarturl(username, url='/'):
    stamp = int(time.time() * 1000)
    id = username
    res = SMART_KEY + str(stamp) + id
    token = hashlib.sha1(res.encode('utf-8')).hexdigest()
    LOGIN_DICT = {
        "id": id,
        "stamp": stamp,
        "token": token,
        "url": url
    }

    # 拼接好的url,直接访问
    visit_url = LOGIN_URL.format(**LOGIN_DICT)
    return visit_url