问题描述
两年前,有人问是否可以programmatically revoke access tokens through the Gitlab API。当时的答案是否定的。我没有找到证实或否认这仍然是真实的最新信息。
我希望在 Python 的 http 请求库中使用这样的东西:
headers = {'Authorization': clientSecret}
res = gitlab.post("https://gitlab.com/oauth/revoke",headers=headers,data={
'client_id': clientID,'access_token': accesstoken
})
print(res.text)
然而,响应是空的,有不同的变化。
解决方法
根据 here 信息,撤销访问令牌似乎是完全可能的。 这有效:
payload = {"token": accessToken,"token_type_hint": "refresh_token"
}
auth = HTTPBasicAuth(clientID,clientSecret)
res = requests.post("https://gitlab.com/oauth/revoke",data=payload,auth=auth,)