• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python datastructures.WWWAuthenticate类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中werkzeug.datastructures.WWWAuthenticate的典型用法代码示例。如果您正苦于以下问题:Python WWWAuthenticate类的具体用法?Python WWWAuthenticate怎么用?Python WWWAuthenticate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: digest_auth

def digest_auth(qop=None, user='user', passwd='passwd'):
    """Prompts the user for authorization using HTTP Digest auth"""
    if qop not in ('auth', 'auth-int'):
        qop = None
    if 'Authorization' not in request.headers or  \
                       not check_digest_auth(user, passwd) or \
                       not 'Cookie' in request.headers:
        response = app.make_response('')
        response.status_code = 401

        # RFC2616 Section4.2: HTTP headers are ASCII.  That means
        # request.remote_addr was originally ASCII, so I should be able to
        # encode it back to ascii.  Also, RFC2617 says about nonces: "The
        # contents of the nonce are implementation dependent"
        nonce = H(b''.join([
            getattr(request,'remote_addr',u'').encode('ascii'),
            b':',
            str(time.time()).encode('ascii'),
            b':',
            os.urandom(10)
        ]))
        opaque = H(os.urandom(10))

        auth = WWWAuthenticate("digest")
        auth.set_digest('[email protected]', nonce, opaque=opaque,
                        qop=('auth', 'auth-int') if qop is None else (qop, ))
        response.headers['WWW-Authenticate'] = auth.to_header()
        response.headers['Set-Cookie'] = 'fake=fake_value'
        return response
    return jsonify(authenticated=True, user=user)
开发者ID:paradisesunny,项目名称:httpbin,代码行数:30,代码来源:core.py


示例2: digest_auth

def digest_auth(qop=None, user="user", passwd="passwd"):
    """Prompts the user for authorization using HTTP Digest auth"""
    if qop not in ("auth", "auth-int"):
        qop = None
    if not request.headers.get("Authorization"):
        response = app.make_response("")
        response.status_code = 401

        # RFC2616 Section4.2: HTTP headers are ASCII.  That means
        # request.remote_addr was originally ASCII, so I should be able to
        # encode it back to ascii.  Also, RFC2617 says about nonces: "The
        # contents of the nonce are implementation dependent"
        nonce = H(
            b"".join(
                [
                    getattr(request, "remote_addr", u"").encode("ascii"),
                    b":",
                    str(time.time()).encode("ascii"),
                    b":",
                    os.urandom(10),
                ]
            )
        )
        opaque = H(os.urandom(10))

        auth = WWWAuthenticate("digest")
        auth.set_digest(
            "[email protected]", nonce, opaque=opaque, qop=("auth", "auth-int") if qop is None else (qop,)
        )
        response.headers["WWW-Authenticate"] = auth.to_header()
        response.headers["Set-Cookie"] = "fake=fake_value"
        return response
    elif not (check_digest_auth(user, passwd) and request.headers.get("Cookie")):
        return status_code(401)
    return jsonify(authenticated=True, user=user)
开发者ID:hickford,项目名称:httpbin,代码行数:35,代码来源:core.py


示例3: handle_unauthorized

def handle_unauthorized():
    authenticate = WWWAuthenticate()
    authenticate.set_basic('AdminLDAP Login')
    response = make_response(error_response(
        u'Authentifizierung erforderlich',401))
    response.headers['WWW-Authenticate'] = authenticate.to_header()
    return response
开发者ID:agdsn,项目名称:adminldap,代码行数:7,代码来源:__init__.py


示例4: digest_auth

def digest_auth(qop=None, user='user', passwd='passwd', checkCookie=True):
    """Prompts the user for authorization using HTTP Digest auth"""
    if qop not in ('auth', 'auth-int'):
        qop = None
    try:
        remoteAddr = request.remote_addr or u''
        authInHeaders = 'Authorization' in request.headers
        digestCheck = authInHeaders and request.headers.get('Authorization').startswith('Digest ')
        authCheck = authInHeaders and digestCheck and check_digest_auth(user, passwd)
        if not all([authInHeaders, digestCheck, authCheck]):
            # RFC2616 Section4.2: HTTP headers are ASCII.  That means
            # request.remote_addr was originally ASCII, so I should be able to
            # encode it back to ascii.  Also, RFC2617 says about nonces: "The
            # contents of the nonce are implementation dependent"
            nonce = H(b':'.join([
                remoteAddr.encode('ascii'),
                str(time.time()).encode('ascii'),
                os.urandom(10)
            ]))
            opaque = H(os.urandom(10))
            
            response = app.make_response(jsonify(
                authenticated=False, user=user, authInHeaders=authInHeaders,
                digestCheck=digestCheck, authCheck=authCheck,
                headers=dict(request.headers)))
            response.status_code = 401
            
            auth = WWWAuthenticate("digest")
            auth.set_digest('[email protected]', nonce, opaque=opaque,
                            qop=('auth', 'auth-int') if qop is None else (qop, ))
            response.headers['WWW-Authenticate'] = auth.to_header()
            if checkCookie is True:
                response.headers['Set-Cookie'] = 'auth=%s' % remoteAddr
            return response
        elif checkCookie is True and request.cookies.get('auth') != remoteAddr:
            # check for auth challange cookie per https://github.com/Runscope/httpbin/issues/124
            response = app.make_response('Missing the cookie set in the 401 response. '
                'This client seems broken. To bypass this check use the digest-auth-nocookie route.')
            response.status_code = 403
            return response
    except Exception as e:
        response = app.make_response('Error: %s' % str(e))
        response.status_code = 500
        return response
    return jsonify(authenticated=True, user=user)
开发者ID:AtnNn,项目名称:rethinkdb,代码行数:45,代码来源:core.py


示例5: digest_auth

def digest_auth(qop=None, user="user", passwd="passwd"):
    """Prompts the user for authorization using HTTP Digest auth"""
    if qop not in ("auth", "auth-int"):
        qop = None
    if not request.headers.get("Authorization"):
        response = app.make_response("")
        response.status_code = 401

        nonce = H("%s:%d:%s" % (request.remote_addr, time.time(), os.urandom(10)))
        opaque = H(os.urandom(10))

        auth = WWWAuthenticate("digest")
        auth.set_digest(
            "[email protected]", nonce, opaque=opaque, qop=("auth", "auth-int") if qop is None else (qop,)
        )
        response.headers["WWW-Authenticate"] = auth.to_header()
        return response
    elif not check_digest_auth(user, passwd):
        return status_code(401)
    return jsonify(authenticated=True, user=user)
开发者ID:playmaker,项目名称:httpbin,代码行数:20,代码来源:core.py


示例6: digest_auth

def digest_auth(qop=None, user='user', passwd='passwd'):
    """Prompts the user for authorization using HTTP Digest auth"""
    if qop not in ('auth', 'auth-int'):
        qop = None
    if not request.headers.get('Authorization'):
        response = app.make_response('')
        response.status_code = 401

        nonce = H("%s:%d:%s" % (request.remote_addr,
                                  time.time(),
                                  os.urandom(10)))
        opaque = H(os.urandom(10))

        auth = WWWAuthenticate("digest")
        auth.set_digest('[email protected]', nonce, opaque=opaque,
                        qop=('auth', 'auth-int') if qop is None else (qop, ))
        response.headers['WWW-Authenticate'] = auth.to_header()
        return response
    elif not check_digest_auth(user, passwd):
        return status_code(403)
    return dict(authenticated=True, user=user)
开发者ID:chaeso,项目名称:httpbin,代码行数:21,代码来源:core.py


示例7: digest_challenge_response

def digest_challenge_response(app, qop, algorithm, stale = False):
    response = app.make_response('')
    response.status_code = 401

    # RFC2616 Section4.2: HTTP headers are ASCII.  That means
    # request.remote_addr was originally ASCII, so I should be able to
    # encode it back to ascii.  Also, RFC2617 says about nonces: "The
    # contents of the nonce are implementation dependent"
    nonce = H(b''.join([
        getattr(request, 'remote_addr', u'').encode('ascii'),
        b':',
        str(time.time()).encode('ascii'),
        b':',
        os.urandom(10)
    ]), algorithm)
    opaque = H(os.urandom(10), algorithm)

    auth = WWWAuthenticate("digest")
    auth.set_digest('[email protected]', nonce, opaque=opaque,
                    qop=('auth', 'auth-int') if qop is None else (qop,), algorithm=algorithm)
    auth.stale = stale
    response.headers['WWW-Authenticate'] = auth.to_header()
    return response
开发者ID:Runscope,项目名称:httpbin,代码行数:23,代码来源:helpers.py


示例8: test_unauthorized_www_authenticate

def test_unauthorized_www_authenticate():
    basic = WWWAuthenticate()
    basic.set_basic("test")
    digest = WWWAuthenticate()
    digest.set_digest("test", "test")

    exc = exceptions.Unauthorized(www_authenticate=basic)
    h = dict(exc.get_headers({}))
    assert h['WWW-Authenticate'] == str(basic)

    exc = exceptions.Unauthorized(www_authenticate=[digest, basic])
    h = dict(exc.get_headers({}))
    assert h['WWW-Authenticate'] == ', '.join((str(digest), str(basic)))
开发者ID:brunoais,项目名称:werkzeug,代码行数:13,代码来源:test_exceptions.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python repr.debug_repr函数代码示例发布时间:2022-05-26
下一篇:
Python datastructures.OrderedMultiDict类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap