当前位置: 首页>>代码示例>>Python>>正文


Python itsdangerous.JSONWebSignatureSerializer方法代码示例

本文整理汇总了Python中itsdangerous.JSONWebSignatureSerializer方法的典型用法代码示例。如果您正苦于以下问题:Python itsdangerous.JSONWebSignatureSerializer方法的具体用法?Python itsdangerous.JSONWebSignatureSerializer怎么用?Python itsdangerous.JSONWebSignatureSerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在itsdangerous的用法示例。


在下文中一共展示了itsdangerous.JSONWebSignatureSerializer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: verify_api_key

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def verify_api_key(api_key):
        """Verify an API key based on the user name

        Returns:
            Actinia Core_api.resources.common.user.ActiniaUser:
            A user object is success or None
        """
        s = JSONWebSignatureSerializer(global_config.SECRET_KEY)

        try:
            data = s.loads(api_key)
        except BadSignature:
            return None

        user = ActiniaUser(data["user_id"])
        if user.exists():
            return user

        return None 
开发者ID:mundialis,项目名称:actinia_core,代码行数:21,代码来源:user.py

示例2: test_missing_algorithm_name

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def test_missing_algorithm_name(self):
        python_node = self.get_ast_node(
            """
            from itsdangerous import JSONWebSignatureSerializer as Serializer

            serializer = Serializer(app.config['SECRET_KEY'])
            """
        )

        linter = dlint.linters.BadItsDangerousKwargUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:18,代码来源:test_bad_itsdangerous_kwarg_use.py

示例3: generate_api_key

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def generate_api_key(self):
        s = JSONWebSignatureSerializer(current_app.config['SECRET_KEY'])
        byte_str = s.dumps({
            'user': str(self.id),
            'time': time(),
        })
        self.apikey = byte_str.decode() 
开发者ID:opendatateam,项目名称:udata,代码行数:9,代码来源:models.py

示例4: confirm_login

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def confirm_login():
    # Check for state and for 0 errors
    state = session.get('oauth2_state')
    if not state or request.values.get('error'):
        return redirect(url_for('index'))

    # Fetch token
    discord = make_session(state=state)
    discord_token = discord.fetch_token(
        TOKEN_URL,
        client_secret=OAUTH2_CLIENT_SECRET,
        authorization_response=request.url)
    if not discord_token:
        return redirect(url_for('index'))

    # Fetch the user
    user = get_user(discord_token)
    if not user:
        return redirect(url_for('logout'))
    # Generate api_key from user_id
    serializer = JSONWebSignatureSerializer(app.config['SECRET_KEY'])
    api_key = str(serializer.dumps({'user_id': user['id']}))
    # Store api_key
    db.set('user:{}:api_key'.format(user['id']), api_key)
    # Store token
    db.set('user:{}:discord_token'.format(user['id']),
           json.dumps(discord_token))
    # Store api_token in client session
    api_token = {
        'api_key': api_key,
        'user_id': user['id']
    }
    session.permanent = True
    session['api_token'] = api_token
    return redirect(url_for('select_server')) 
开发者ID:cookkkie,项目名称:mee6,代码行数:37,代码来源:app.py

示例5: generate_api_key

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def generate_api_key(self):
        """Generate an API key based on the user id

        Returns:
            str:
            API key
        """
        s = JSONWebSignatureSerializer(global_config.SECRET_KEY)
        return s.dumps({"user_id":self.user_id}) 
开发者ID:mundialis,项目名称:actinia_core,代码行数:11,代码来源:user.py

示例6: generate_token

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def generate_token(tenant: Tenant) -> bytes:
    s = JSONWebSignatureSerializer(current_app.secret_key, salt="auth")
    payload: Dict[str, Any] = {
        "access": {str(k): int(v) if v else None for k, v in tenant.access.items()}
    }
    if getattr(tenant, "user_id", None):
        payload["uid"] = str(tenant.user_id)
    return s.dumps(payload) 
开发者ID:getsentry,项目名称:zeus,代码行数:10,代码来源:auth.py

示例7: parse_token

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def parse_token(token: str) -> Optional[Any]:
    s = JSONWebSignatureSerializer(current_app.secret_key, salt="auth")
    try:
        return s.loads(token)

    except BadSignature:
        return None 
开发者ID:getsentry,项目名称:zeus,代码行数:9,代码来源:auth.py

示例8: init_app

# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def init_app(app):
    if not app.secret_key:
        logger.warning("The `SECRET_KEY` setting is not set; tokens will be signed with "
                       "an insecure, static key")
    secret_key = app.secret_key or 'NOT THAT SECRET'
    app.tokenauth_serializer = JSONWebSignatureSerializer(secret_key) 
开发者ID:mozilla,项目名称:build-relengapi,代码行数:8,代码来源:tokenstr.py


注:本文中的itsdangerous.JSONWebSignatureSerializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。