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


Python oauth2.Client类代码示例

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

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

示例1: test_client_secret_post

def test_client_secret_post():
    client = Client("A")
    client.client_secret = "boarding pass"

    cis = AccessTokenRequest(code="foo", redirect_uri="http://example.com")

    csp = ClientSecretPost(client)
    http_args = csp.construct(cis)

    print cis
    assert cis["client_id"] == "A"
    assert cis["client_secret"] == "boarding pass"
    print http_args
    assert http_args is None

    cis = AccessTokenRequest(code="foo", redirect_uri="http://example.com")

    request_args = {}
    http_args = csp.construct(cis, request_args,
                              http_args={"client_secret": "another"})

    print cis
    assert cis["client_id"] == "A"
    assert cis["client_secret"] == "another"
    print http_args
    assert http_args == {}
开发者ID:dajiaji,项目名称:pyoidc,代码行数:26,代码来源:test_oauth2.py


示例2: test_bearer_header_with_http_args

def test_bearer_header_with_http_args():
    client = Client("A")
    client.client_secret = "boarding pass"

    request_args = {"access_token": "Sesame"}

    cis = ResourceRequest()

    bh = BearerHeader(client)
    http_args = bh.construct(cis, request_args, http_args={"foo": "bar"})

    print cis
    print http_args
    assert _eq(http_args.keys(), ["foo", "headers"])
    assert http_args["headers"] == {"Authorization": "Bearer Sesame"}

    # -----------------

    request_args = {"access_token": "Sesame"}

    bh = BearerHeader(client)
    http_args = bh.construct(cis, request_args,
                             http_args={"headers": {"x-foo": "bar"}})

    print cis
    print http_args
    assert _eq(http_args.keys(), ["headers"])
    assert _eq(http_args["headers"].keys(), ["Authorization", "x-foo"])
    assert http_args["headers"]["Authorization"] == "Bearer Sesame"
开发者ID:dajiaji,项目名称:pyoidc,代码行数:29,代码来源:test_oauth2.py


示例3: test_bearer_body

def test_bearer_body():
    client = Client("A")
    client.client_secret = "boarding pass"

    request_args = {"access_token": "Sesame"}

    cis = ResourceRequest()
    http_args = BearerBody(client).construct(cis, request_args)
    assert cis["access_token"] == "Sesame"
    print http_args
    assert http_args is None

    # ----------
    resp = AuthorizationResponse(code="code", state="state")
    grant = Grant()
    grant.add_code(resp)

    atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
                              token_type="example",
                              refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
                              example_parameter="example_value",
                              scope=["inner", "outer"])

    grant.add_token(atr)
    client.grant["state"] = grant

    cis = ResourceRequest()
    http_args = BearerBody(client).construct(cis, {}, state="state",
                                             scope="inner")
    assert cis["access_token"] == "2YotnFZFEjr1zCsicMWpAA"
    print http_args
    assert http_args is None
开发者ID:dajiaji,项目名称:pyoidc,代码行数:32,代码来源:test_oauth2.py


示例4: test_client_secret_basic

def test_client_secret_basic():
    client = Client("A")
    client.client_secret = "boarding pass"

    cis = AccessTokenRequest(code="foo", redirect_uri="http://example.com")

    http_args = oauth2.client_secret_basic(client, cis)

    assert http_args == {"auth": ("A", "boarding pass")}
开发者ID:asheidan,项目名称:pyoidc,代码行数:9,代码来源:test_oauth2.py


示例5: test_construct_access_token_req_expired_grant

    def test_construct_access_token_req_expired_grant(self):
        resp = AuthorizationResponse(code="code", state="state")
        grant = Grant(-10)  # expired grant
        grant.add_code(resp)

        client = Client()
        client.grant["openid"] = grant
        with pytest.raises(GrantExpired):
            client.construct_AccessTokenRequest(state="openid")
开发者ID:joostd,项目名称:pyoidc,代码行数:9,代码来源:test_oauth2.py


示例6: test_client_secret_basic

def test_client_secret_basic():
    client = Client("A")
    client.client_secret = "boarding pass"

    cis = AccessTokenRequest(code="foo", redirect_uri="http://example.com")

    csb = ClientSecretBasic(client)
    http_args = csb.construct(cis)

    assert http_args == {"headers": {'Authorization': 'Basic %s'
                                     % base64.b64encode('A:boarding pass')}}
开发者ID:dajiaji,项目名称:pyoidc,代码行数:11,代码来源:test_oauth2.py


示例7: phaseN

    def phaseN(self, environ, info, server_env, sid):
        session = server_env["CACHE"][sid]

        callback = server_env["base_url"] + self.social_endpoint

        client = Client(client_id=self.client_id,
                        client_authn_method=CLIENT_AUTHN_METHOD)
        response = client.parse_response(AuthorizationResponse, info, "dict")
        logger.info("Response: %s" % response)

        if isinstance(response, ErrorResponse):
            logger.info("%s" % response)
            session["authentication"] = "FAILED"
            return False, "Authentication failed or permission not granted"

        req_args = {
            "redirect_uri": callback,
            "client_secret": self.client_secret,
        }

        client.token_endpoint = self.extra["token_endpoint"]
        tokenresp = client.do_access_token_request(
            scope=self._scope,
            body_type=self.token_response_body_type,
            request_args=req_args,
            authn_method="client_secret_post",
            state=response["state"],
            response_cls=self.access_token_response)

        if isinstance(tokenresp, ErrorResponse):
            logger.info("%s" % tokenresp)
            session["authentication"] = "FAILED"
            return False, "Authentication failed or permission not granted"

        # Download the user profile and cache a local instance of the
        # basic profile info
        result = client.fetch_protected_resource(
            self.userinfo_endpoint(tokenresp), token=tokenresp["access_token"])

        logger.info("Userinfo: %s" % result.text)
        root = ET.fromstring(result.text)
        jsontext = json.dumps(root.attrib)
        profile = json.loads(jsontext)
        profile = self.convert(profile)
        logger.info("PROFILE: %s" % (profile, ))
        session["service"] = self.name
        session["authentication"] = "OK"
        session["status"] = "SUCCESS"
        session["authn_auth"] = self.authenticating_authority
        session["permanent_id"] = profile["uid"]

        server_env["CACHE"][sid] = session

        return True, profile, session
开发者ID:HaToHo,项目名称:IdPproxy,代码行数:54,代码来源:__init__.py


示例8: test_get_access_token_request

def test_get_access_token_request():
    resp = AuthorizationResponse(code="code", state="state")
    grant = Grant(1)
    grant.add_code(resp)

    client = Client()
    client.grant["openid"] = grant
    time.sleep(2)
    try:
        client.construct_AccessTokenRequest(state="openid")
    except Exception, err:
        assert err.__class__.__name__ == "GrantExpired"
开发者ID:dajiaji,项目名称:pyoidc,代码行数:12,代码来源:test_oauth2.py


示例9: test_bearer_header_2

def test_bearer_header_2():
    client = Client("A")
    client.client_secret = "boarding pass"

    cis = ResourceRequest(access_token="Sesame")

    http_args = oauth2.bearer_header(client, cis)

    print cis
    assert "access_token" not in cis
    print http_args
    assert http_args == {"headers": {"Authorization": "Bearer Sesame"}}
开发者ID:asheidan,项目名称:pyoidc,代码行数:12,代码来源:test_oauth2.py


示例10: test_client_get_grant

def test_client_get_grant():
    cli = Client()

    resp = AuthorizationResponse(code="code", state="state")
    grant = Grant()
    grant.add_code(resp)

    cli.grant["state"] = grant

    gr1 = cli.grant_from_state("state")

    assert gr1.code == "code"
开发者ID:dajiaji,项目名称:pyoidc,代码行数:12,代码来源:test_oauth2.py


示例11: test_pkce_verify_512

    def test_pkce_verify_512(self, session_db_factory):
        _cli = Client(config={'code_challenge': {'method': 'S512', 'length': 96}})
        args, cv = _cli.add_code_challenge()

        authn_broker = AuthnBroker()
        authn_broker.add("UNDEFINED", DummyAuthn(None, "username"))
        _prov = Provider("as",
                         session_db_factory('https://connect-op.heroku.com'), {},
                         authn_broker, Implicit(), verify_client)

        assert _prov.verify_code_challenge(cv, args['code_challenge'], 'S512') is True
        resp = _prov.verify_code_challenge('XXX', args['code_challenge'])
        assert isinstance(resp, Response)
        assert resp.info()['status_code'] == 401
开发者ID:,项目名称:,代码行数:14,代码来源:


示例12: test_parse_access_token_response_missing_attribute

def test_parse_access_token_response_missing_attribute():
    at = AccessTokenResponse(access_token="SlAV32hkKG", token_type="Bearer", refresh_token="8xLOxBtZp8", expire_in=3600)

    atdict = at.to_dict()
    del atdict["access_token"]
    atj = json.dumps(atdict)
    print atj
    client = Client()
    ATR = AccessTokenResponse

    try:
        client.parse_response(ATR, info=atj)
    except Exception, err:
        assert err.__class__.__name__ == "MissingRequiredAttribute"
开发者ID:asheidan,项目名称:pyoidc,代码行数:14,代码来源:test_oauth2.py


示例13: test_client_parse_extra_args

def test_client_parse_extra_args():
    cli = Client()

    args = {
        "response_type": "",
        "client_id": "client_id",
        "redirect_uri": "http://example.com/authz",
        "scope": "scope",
        "state": "state",
        "extra_session": "home",
    }
    ar_args = cli._parse_args(AuthorizationRequest, **args)

    assert _eq(ar_args.keys(), ["state", "redirect_uri", "response_type", "client_id", "scope", "extra_session"])
开发者ID:asheidan,项目名称:pyoidc,代码行数:14,代码来源:test_oauth2.py


示例14: test_bearer_header

def test_bearer_header():
    client = Client("A")
    client.client_secret = "boarding pass"

    request_args = {"access_token": "Sesame"}

    cis = ResourceRequest()

    bh = BearerHeader(client)
    http_args = bh.construct(cis, request_args)

    print cis
    print http_args
    assert http_args == {"headers": {"Authorization": "Bearer Sesame"}}
开发者ID:dajiaji,项目名称:pyoidc,代码行数:14,代码来源:test_oauth2.py


示例15: test_private_key_jwt

def test_private_key_jwt():
    cli = Client("FOO")
    cli.token_endpoint = "https://example.com/token"
    cli.keyjar[""] = KC_RSA

    cis = AccessTokenRequest()
    pkj = PrivateKeyJWT(cli)
    http_args = pkj.construct(cis, algorithm="RS256")
    assert http_args == {}
    cas = cis["client_assertion"]
    header, claim, crypto, header_b64, claim_b64 = jwkest.unpack(cas)
    jso = json.loads(claim)
    assert _eq(jso.keys(), ["aud", "iss", "sub", "jti", "exp", "iat"])
    print header
    assert header == {'alg': 'RS256'}
开发者ID:ghedin,项目名称:pyoidc,代码行数:15,代码来源:test_authn.py


示例16: test_client_parse_args

def test_client_parse_args():
    cli = Client()

    args = {
        "response_type": "",
        "client_id": "client_id",
        "redirect_uri": "http://example.com/authz",
        "scope": "scope",
        "state": "state",
    }

    ar_args = cli._parse_args(AuthorizationRequest, **args)

    assert _eq(ar_args.keys(), ['scope', 'state', 'redirect_uri',
                                'response_type', 'client_id'])
开发者ID:dajiaji,项目名称:pyoidc,代码行数:15,代码来源:test_oauth2.py


示例17: create_client

    def create_client(self):
        self.redirect_uri = "https://example.com/redirect"
        self.authorization_endpoint = "https://example.com/authz"

        self.client = Client("1", config={'issuer': 'https://example.com/as'})
        self.client.redirect_uris = [self.redirect_uri]
        self.client.response_type = "code"
        self.client.authorization_endpoint = self.authorization_endpoint
开发者ID:Omosofe,项目名称:pyoidc,代码行数:8,代码来源:test_oauth2.py


示例18: create_client

    def create_client(self):
        self.redirect_uri = "https://example.com/redirect"
        self.authorization_endpoint = "https://example.com/authz"

        self.client = Client("1")  # pylint: disable=attribute-defined-outside-init
        self.client.redirect_uris = [self.redirect_uri]
        self.client.response_type = "code"
        self.client.authorization_endpoint = self.authorization_endpoint
开发者ID:joostd,项目名称:pyoidc,代码行数:8,代码来源:test_oauth2.py


示例19: __init__

    def __init__(
        self,
        session_db,
        client_config=None,
        server_info=None,
        authz_page="",
        response_type="",
        scope="",
        flow_type="",
        password=None,
    ):
        """ Initializes a Consumer instance.

        :param session_db: Where info are kept about sessions acts like a
            dictionary
        :param client_config: Client configuration
        :param server_info: Information about the server
        :param authz_page:
        :param response_type:
        :param scope:
        :param flow_type:
        """
        if client_config is None:
            client_config = {}

        Client.__init__(self, **client_config)

        self.authz_page = authz_page
        self.response_type = response_type
        self.scope = scope
        self.flow_type = flow_type
        self.password = password

        if server_info:
            for endpoint in ENDPOINTS:
                try:
                    setattr(self, endpoint, server_info[endpoint])
                except KeyError:
                    setattr(self, endpoint, None)
        else:
            for endpoint in ENDPOINTS:
                setattr(self, endpoint, None)

        self.sdb = session_db
        self.seed = rndstr()
开发者ID:biancini,项目名称:pyoidc,代码行数:45,代码来源:consumer.py


示例20: phaseN

    def phaseN(self, environ, query, server_env, session):
        callback = server_env["base_url"] + self.opKey

        client = Client(client_id=self.client_id,
                        client_authn_method=CLIENT_AUTHN_METHOD)
        response = client.parse_response(AuthorizationResponse, query, "dict")
        logger.info("Response: %s" % response)

        if isinstance(response, ErrorResponse):
            logger.info("%s" % response)
            return (False, "Authentication failed or permission not granted")

        req_args = {
            "redirect_uri": callback,
            "client_secret": self.client_secret,
        }

        client.token_endpoint = self.extra["token_endpoint"]
        tokenresp = client.do_access_token_request(
            scope=self._scope,
            body_type=self.token_response_body_type,
            request_args=req_args,
            authn_method="client_secret_post",
            state=response["state"],
            response_cls=self.access_token_response)

        if isinstance(tokenresp, ErrorResponse):
            logger.info("%s" % tokenresp)
            return (False, "Authentication failed or permission not granted")

        # Download the user profile and cache a local instance of the
        # basic profile info
        result = client.fetch_protected_resource(
            self.userinfo_endpoint(tokenresp), token=tokenresp["access_token"])

        logger.info("Userinfo: %s" % result.text)
        profile = json.loads(result.text)

        return True, profile, tokenresp["access_token"], client
开发者ID:dash-dash,项目名称:pyoidc,代码行数:39,代码来源:__init__.py



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