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


Python message.AccessTokenRequest类代码示例

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


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

示例1: test_token_endpoint_unauth

    def test_token_endpoint_unauth(self):
        authreq = AuthorizationRequest(state="state",
                                       redirect_uri="http://example.com/authz",
                                       client_id="client_1")

        _sdb = self.server.sdb
        sid = _sdb.token.key(user="sub", areq=authreq)
        access_grant = _sdb.token(sid=sid)
        ae = AuthnEvent("user")
        _sdb[sid] = {
            "authn_event": ae,
            "oauth_state": "authz",
            "authzreq": "",
            "client_id": "client_1",
            "code": access_grant,
            "code_used": False,
            "scope": ["openid"],
            "redirect_uri": "http://example.com/authz"
        }
        _sdb.do_sub(sid)

        # Construct Access token request
        areq = AccessTokenRequest(code=access_grant,
                                  redirect_uri="http://example.com/authz",
                                  client_id="client_1", client_secret="secret", )

        print areq.to_dict()
        txt = areq.to_urlencoded()

        resp = self.server.token_endpoint(request=txt, remote_user="client2",
                                          request_method="POST")
        print resp
        atr = TokenErrorResponse().deserialize(resp.message, "json")
        print atr.keys()
        assert _eq(atr.keys(), ['error'])
开发者ID:dallerbarn,项目名称:pyoidc,代码行数:35,代码来源:test_oic_provider.py

示例2: token_endpoint

    def token_endpoint(self, dtype='urlencoded', **kwargs):
        atr = AccessTokenRequest().deserialize(kwargs["request"], dtype)
        resp = super(PoPProvider, self).token_endpoint(**kwargs)

        if "token_type" not in atr or atr["token_type"] != "pop":
            return resp

        client_public_key = base64.urlsafe_b64decode(
            atr["key"].encode("utf-8")).decode("utf-8")
        pop_key = json.loads(client_public_key)
        atr = AccessTokenResponse().deserialize(resp.message, method="json")
        data = self.sdb.read(atr["access_token"])

        jwt = {"iss": self.baseurl,
               "aud": self.baseurl,
               "exp": data["token_expires_at"],
               "nbf": int(time.time()),
               "cnf": {"jwk": pop_key}}
        _jws = JWS(jwt, alg="RS256").sign_compact(
            self.keyjar.get_signing_key(owner=""))
        self.access_tokens[_jws] = data["access_token"]

        atr["access_token"] = _jws
        atr["token_type"] = "pop"
        return Response(atr.to_json(), content="application/json")
开发者ID:Omosofe,项目名称:pyoidc,代码行数:25,代码来源:proof_of_possesion.py

示例3: test_server_parse_token_request

def test_server_parse_token_request():
    atr = AccessTokenRequest(grant_type="authorization_code",
                             code="SplxlOBeZQQYbYS6WxSbIA",
                             redirect_uri="https://client.example.com/cb",
                             client_id=CLIENT_ID, extra="foo")

    uenc = atr.to_urlencoded()

    srv = Server()
    srv.keyjar = KEYJ
    tr = srv.parse_token_request(body=uenc)
    print tr.keys()

    assert tr.type() == "AccessTokenRequest"
    assert _eq(tr.keys(), ['code', 'redirect_uri', 'grant_type', 'client_id',
                           'extra'])

    assert tr["grant_type"] == "authorization_code"
    assert tr["code"] == "SplxlOBeZQQYbYS6WxSbIA"

    tr = srv.parse_token_request(body=uenc)
    print tr.keys()

    assert tr.type() == "AccessTokenRequest"
    assert _eq(tr.keys(), ['code', 'grant_type', 'client_id', 'redirect_uri',
                           'extra'])

    assert tr["extra"] == "foo"
开发者ID:dash-dash,项目名称:pyoidc,代码行数:28,代码来源:test_oic.py

示例4: test_token_endpoint

    def test_token_endpoint(self):
        authreq = AuthorizationRequest(state="state",
                                       redirect_uri="http://example.com/authz",
                                       client_id=CLIENT_ID,
                                       response_type="code",
                                       scope=["openid"])

        _sdb = self.provider.sdb
        sid = _sdb.token.key(user="sub", areq=authreq)
        access_grant = _sdb.token(sid=sid)
        ae = AuthnEvent("user", "salt")
        _sdb[sid] = {
            "oauth_state": "authz",
            "authn_event": ae,
            "authzreq": authreq.to_json(),
            "client_id": CLIENT_ID,
            "code": access_grant,
            "code_used": False,
            "scope": ["openid"],
            "redirect_uri": "http://example.com/authz",
        }
        _sdb.do_sub(sid, "client_salt")

        # Construct Access token request
        areq = AccessTokenRequest(code=access_grant, client_id=CLIENT_ID,
                                  redirect_uri="http://example.com/authz",
                                  client_secret=CLIENT_SECRET)

        txt = areq.to_urlencoded()

        resp = self.provider.token_endpoint(request=txt)
        atr = AccessTokenResponse().deserialize(resp.message, "json")
        assert _eq(atr.keys(),
                   ['token_type', 'id_token', 'access_token', 'scope',
                    'expires_in', 'refresh_token'])
开发者ID:joostd,项目名称:pyoidc,代码行数:35,代码来源:test_oic_provider.py

示例5: test_token_endpoint_malformed

    def test_token_endpoint_malformed(self):
        authreq = AuthorizationRequest(state="state",
                                       redirect_uri="http://example.com/authz",
                                       client_id=CLIENT_ID,
                                       response_type="code",
                                       scope=["openid"])

        _sdb = self.provider.sdb
        sid = _sdb.access_token.key(user="sub", areq=authreq)
        access_grant = _sdb.access_token(sid=sid)
        ae = AuthnEvent("user", "salt")
        _sdb[sid] = {
            "oauth_state": "authz",
            "authn_event": ae,
            "authzreq": authreq.to_json(),
            "client_id": CLIENT_ID,
            "code": access_grant,
            "code_used": False,
            "scope": ["openid"],
            "redirect_uri": "http://example.com/authz",
        }
        _sdb.do_sub(sid, "client_salt")

        # Construct Access token request
        areq = AccessTokenRequest(code=access_grant[0:len(access_grant) - 1],
                                  client_id=CLIENT_ID,
                                  redirect_uri="http://example.com/authz",
                                  client_secret=CLIENT_SECRET,
                                  grant_type='authorization_code')

        txt = areq.to_urlencoded()

        resp = self.provider.token_endpoint(request=txt)
        atr = TokenErrorResponse().deserialize(resp.message, "json")
        assert atr['error'] == "access_denied"
开发者ID:danielquinn,项目名称:pyoidc,代码行数:35,代码来源:test_oic_provider.py

示例6: test_token_endpoint

def test_token_endpoint():
    server = provider_init

    authreq = AuthorizationRequest(state="state",
                                   redirect_uri="http://example.com/authz",
                                   client_id=CLIENT_ID)

    _sdb = server.sdb
    sid = _sdb.token.key(user="user_id", areq=authreq)
    access_grant = _sdb.token(sid=sid)
    _sdb[sid] = {
        "oauth_state": "authz",
        "sub": "user_id",
        "authzreq": "",
        "client_id": CLIENT_ID,
        "code": access_grant,
        "code_used": False,
        "scope": ["openid"],
        "redirect_uri": "http://example.com/authz"
    }

    # Construct Access token request
    areq = AccessTokenRequest(code=access_grant, client_id=CLIENT_ID,
                              redirect_uri="http://example.com/authz",
                              client_secret=CLIENT_SECRET)

    txt = areq.to_urlencoded()

    resp = server.token_endpoint(request=txt)
    print resp
    atr = AccessTokenResponse().deserialize(resp.message, "json")
    print atr.keys()
    assert _eq(atr.keys(), ['token_type', 'id_token', 'access_token', 'scope',
                            'expires_in', 'refresh_token'])
开发者ID:biancini,项目名称:pyoidc,代码行数:34,代码来源:test_oic_provider.py

示例7: test_server_parse_token_request

def test_server_parse_token_request():
    atr = AccessTokenRequest(
        grant_type="authorization_code",
        code="SplxlOBeZQQYbYS6WxSbIA",
        redirect_uri="https://client.example.com/cb",
        client_id="client_id",
        extra="foo",
    )

    uenc = atr.to_urlencoded()

    srv = Server()
    tr = srv.parse_token_request(body=uenc)
    print tr.keys()

    assert tr.type() == "AccessTokenRequest"
    assert _eq(tr.keys(), ["code", "redirect_uri", "grant_type", "client_id", "extra"])

    assert tr["grant_type"] == "authorization_code"
    assert tr["code"] == "SplxlOBeZQQYbYS6WxSbIA"

    tr = srv.parse_token_request(body=uenc)
    print tr.keys()

    assert tr.type() == "AccessTokenRequest"
    assert _eq(tr.keys(), ["code", "grant_type", "client_id", "redirect_uri", "extra"])

    assert tr["extra"] == "foo"
开发者ID:imsoftware,项目名称:pyoidc,代码行数:28,代码来源:test_oic.py

示例8: setup_token_endpoint

 def setup_token_endpoint(self):
     authreq = AuthorizationRequest(state="state",
                                    redirect_uri=self.redirect_urls[0],
                                    client_id=CLIENT_ID,
                                    response_type="code",
                                    scope=["openid"])
     _sdb = self.provider.sdb
     sid = _sdb.token.key(user="sub", areq=authreq)
     access_grant = _sdb.token(sid=sid)
     ae = AuthnEvent("user", "salt")
     _sdb[sid] = {
         "oauth_state": "authz",
         "authn_event": ae,
         "authzreq": authreq.to_json(),
         "client_id": CLIENT_ID,
         "code": access_grant,
         "code_used": False,
         "scope": ["openid"],
         "redirect_uri": self.redirect_urls[0],
     }
     _sdb.do_sub(sid, "client_salt")
     # Construct Access token request
     areq = AccessTokenRequest(code=access_grant, client_id=CLIENT_ID,
                               redirect_uri=self.redirect_urls[0],
                               client_secret="client_secret_1")
     txt = areq.to_urlencoded()
     resp = self.provider.token_endpoint(request=txt)
     responses.add(
         responses.POST,
         self.op_base + "token",
         body=resp.message,
         status=200,
         content_type='application/json')
开发者ID:borgand,项目名称:SATOSA,代码行数:33,代码来源:FakeOp.py

示例9: test_parse_token_request

 def test_parse_token_request(self):
     treq = AccessTokenRequest(code="code",
                               redirect_uri="http://example.com/authz",
                               client_id=CLIENT_ID)
     qdict = self.srv.parse_token_request(body=treq.to_urlencoded())
     assert isinstance(qdict, AccessTokenRequest)
     assert _eq(qdict.keys(), ['code', 'redirect_uri', 'client_id',
                               'grant_type'])
     assert qdict["client_id"] == CLIENT_ID
     assert qdict["code"] == "code"
开发者ID:CompanyOnTheWorld,项目名称:pyoidc,代码行数:10,代码来源:test_oic.py

示例10: _pop_token_req

 def _pop_token_req(self, authz_resp):
     pop_key = base64.urlsafe_b64encode(
         json.dumps(self._get_rsa_jwk()).encode("utf-8")).decode("utf-8")
     areq = AccessTokenRequest(code=authz_resp["code"],
                               redirect_uri="http://localhost:8087/authz",
                               client_id="client1",
                               client_secret="drickyoghurt",
                               token_type="pop",
                               key=pop_key)
     resp = self.provider.token_endpoint(request=areq.to_urlencoded(),
                                         request_method="POST")
     return AccessTokenResponse().deserialize(resp.message, "json")
开发者ID:its-dirg,项目名称:proof-of-possession,代码行数:12,代码来源:test_PoPProvider.py

示例11: test_server_parse_token_request

    def test_server_parse_token_request(self):
        atr = AccessTokenRequest(grant_type="authorization_code",
                                 code="SplxlOBeZQQYbYS6WxSbIA",
                                 redirect_uri="https://client.example.com/cb",
                                 client_id=CLIENT_ID, extra="foo")

        uenc = atr.to_urlencoded()

        tr = self.srv.parse_token_request(body=uenc)

        assert isinstance(tr, AccessTokenRequest)
        assert _eq(tr.keys(),
                   ['code', 'redirect_uri', 'grant_type', 'client_id',
                    'extra'])
        assert tr["grant_type"] == "authorization_code"
        assert tr["code"] == "SplxlOBeZQQYbYS6WxSbIA"
        assert tr["extra"] == "foo"
开发者ID:StudienprojektUniTrier,项目名称:Authorization-Server,代码行数:17,代码来源:test_oic.py

示例12: test_token_endpoint

def test_token_endpoint():
    server = provider_init

    authreq = AuthorizationRequest(state="state",
                                   redirect_uri="http://example.com/authz",
                                   client_id=CLIENT_ID)

    _sdb = server.sdb
    sid = _sdb.token.key(user="user_id", areq=authreq)
    access_grant = _sdb.token(sid=sid)
    _sdb[sid] = {
        "oauth_state": "authz",
        "sub": "user_id",
        "authzreq": "",
        "client_id": CLIENT_ID,
        "code": access_grant,
        "code_used": False,
        "scope": ["openid"],
        "redirect_uri":"http://example.com/authz"
    }

    # Construct Access token request
    areq = AccessTokenRequest(code=access_grant, client_id=CLIENT_ID,
                              redirect_uri="http://example.com/authz",
                              client_secret=CLIENT_SECRET)


    str = areq.to_urlencoded()
    fil = StringIO.StringIO(buf=str)
    environ = BASE_ENVIRON.copy()
    environ["REQUEST_METHOD"] = "POST"
    environ["CONTENT_LENGTH"] = len(str)
    environ["wsgi.input"] = fil
    environ["REMOTE_USER"] = CLIENT_ID

    resp = server.token_endpoint(environ, start_response)
    print resp
    atr = AccessTokenResponse().deserialize(resp[0], "json")
    print atr.keys()
    assert _eq(atr.keys(), ['token_type', 'id_token', 'access_token', 'scope',
                            'expires_in', 'refresh_token'])
开发者ID:asheidan,项目名称:pyoidc,代码行数:41,代码来源:test_oic_provider.py

示例13: test_token_endpoint_unauth

    def test_token_endpoint_unauth(self):
        state = 'state'
        authreq = AuthorizationRequest(state=state,
                                       redirect_uri="http://example.com/authz",
                                       client_id="client_1")

        _sdb = self.provider.sdb
        sid = _sdb.access_token.key(user="sub", areq=authreq)
        access_grant = _sdb.access_token(sid=sid)
        ae = AuthnEvent("user", "salt")
        _sdb[sid] = {
            "authn_event": ae,
            "oauth_state": "authz",
            "authzreq": "",
            "client_id": "client_1",
            "code": access_grant,
            "code_used": False,
            "scope": ["openid"],
            "redirect_uri": "http://example.com/authz",
            'state': state
        }
        _sdb.do_sub(sid, "client_salt")

        # Construct Access token request
        areq = AccessTokenRequest(code=access_grant,
                                  redirect_uri="http://example.com/authz",
                                  client_id="client_1",
                                  client_secret="secret",
                                  state=state,
                                  grant_type='authorization_code')

        txt = areq.to_urlencoded()

        resp = self.provider.token_endpoint(request=txt, remote_user="client2",
                                            request_method="POST")
        atr = TokenErrorResponse().deserialize(resp.message, "json")
        assert atr["error"] == "unauthorized_client"
开发者ID:danielquinn,项目名称:pyoidc,代码行数:37,代码来源:test_oic_provider.py


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