當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。