Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest lepture/authlib OAuth2客户端和会话之间有什么区别?_Rest_Api_Oauth 2.0_Authlib - Fatal编程技术网

Rest lepture/authlib OAuth2客户端和会话之间有什么区别?

Rest lepture/authlib OAuth2客户端和会话之间有什么区别?,rest,api,oauth-2.0,authlib,Rest,Api,Oauth 2.0,Authlib,我正在实现一个OAuth2客户端应用程序来连接到服务器。到目前为止,我已经设法使用Authlib的实例获取resource/api/me。我已经尝试过了,但是没有成功,尽管客户机类有像put、post、get、delete这样的方法,所以我认为它适合访问资源/ 那么区别是什么呢?为什么我可以使用会话的实例访问/api/me,而不能使用客户端的实例 这是我的密码: def api_me_get2(token): print("============================

我正在实现一个OAuth2客户端应用程序来连接到服务器。到目前为止,我已经设法使用Authlib的实例获取resource/api/me。我已经尝试过了,但是没有成功,尽管客户机类有像
put、post、get、delete这样的方法,所以我认为它适合访问资源/

那么区别是什么呢?为什么我可以使用会话的实例访问
/api/me
,而不能使用客户端的实例

这是我的密码:

    def api_me_get2(token):
    print("========================================")
    print("Sending 2nd GET request to get protected data of me")

    oauth2_client = OAuthClient(
        client_id='ySFTzBKLo0XTaK2tQL9ls4Fc',
        client_secret='vq8vMZplY4J00FrxKx4ynV2mhmL2zzjMzP1U2bXZPhQRcmJl',
        api_base_url=_url(""),
        access_token_url=_url(f"/oauth/token"),
        authorize_url=_url("/oauth/authorize"),
        client_kwargs={"scope":"profile"},
#        client_kwargs={'scope': 'user:email'},
    )

    new_token = oauth2_client.fetch_access_token();
    print(f"New token \"{new_token}\"")
    # FORM data
    '''
    payload = {
        "token":f"{token}"
    }
    print(f"PAYLOAD=\"{payload}\"")
    r = requests.get(_url(f"/api/me"), data=payload, params=payload)
    print(f"RESPONSE {r.status_code}")
    print(f"r.url={r.url}")
    print(f"r.text={r.text}")
    if r.status_code == 200:
        json = r.json()
        print(f"JSON=\"{json}\"")
    '''
    print("========================================")

def api_me_get3(token):
    print("========================================")
    print("Sending 3rd GET request to get protected data of me")

    oauth2_session = OAuth2Session(
        client_id="ySFTzBKLo0XTaK2tQL9ls4Fc",
        client_secret="vq8vMZplY4J00FrxKx4ynV2mhmL2zzjMzP1U2bXZPhQRcmJl",
        token_endpoint_auth_method=None,
        refresh_token_url=_url("/oauth/revoke"),
        refresh_token_params=None,
        scope="profile",
        redirect_uri=None,
        token=token,
        token_placement='header',
        state=None,
        token_updater=None
    )

    r = oauth2_session.request("GET", _url("/api/me"), withhold_token=False, auth=None)

    print(f"Request: \"{r}\"")

    print(f"RESPONSE {r.status_code}")
    print(f"r.url={r.url}")
    print(f"r.text={r.text}")
    if r.status_code == 200:
        json = r.json()
        print(f"JSON=\"{json}\"")

#    new_token = oauth2_client.fetch_access_token();
#    print(f"New token \"{new_token}\"")
    # FORM data
    '''
    payload = {
        "token":f"{token}"
    }
    print(f"PAYLOAD=\"{payload}\"")
    r = requests.get(_url(f"/api/me"), data=payload, params=payload)
    print(f"RESPONSE {r.status_code}")
    print(f"r.url={r.url}")
    print(f"r.text={r.text}")
    if r.status_code == 200:
        json = r.json()
        print(f"JSON=\"{json}\"")
    '''
    print("========================================")

OAuthClient用于创建框架集成。例如:


如果我想发出请求,我必须创建
client=OAuthClient(…)
的实例,然后使用client.get()、client.post()等,这样的想法是否正确??因为这对我不起作用。它仅适用于
session=OAuth2Session(…)
。但是在会话中。。。我不明白如果我想提出个人请求,为什么我需要会话。