我正在尝试将成功的 python (flask) OAuth 2.0 身份验证/api 请求转换为 Postman。
我目前的流程是:
从前端,我使用 fetch 在 python 中命中了一个 /auth
端点:
fetch("/auth")
.then(function (response) {
return response.json();
})
.then(function (json) {
const code = json.code;
window.location = `[hostname.com]/auth/authorize?request_token=${code}&redirect_uri=http://[hostname]/menu`;
});
后端烧瓶 auth
端点如下所示:
url = 'https://[hostname].com/v3/oauth/request'
headers = CaseInsensitiveDict()
headers['Host'] = '[hostname].com'
headers['Content-Type'] = 'application/json'
headers['X-Accept'] = 'application/json'
data = json.dumps({'consumer_key': 'XXXX', 'redirect_uri':'[hostname]/success'})
resp = requests.post(url, headers=headers, data=data)
json_resp = json.loads(resp.content)
auth_code = json_resp['code']
auth_resp = {'code': auth_code}
return jsonify(auth_resp)
access
端点使用该授权码来获取令牌
cur_auth = session.get('auth_code',None)
url = 'https://[hostname.com]/v3/oauth/authorize'
headers = CaseInsensitiveDict()
headers['Host'] = '[hostname].com'
headers['Content-Type'] = 'application/json; charset=UTF-8'
headers['X-Accept'] = 'application/json'
data = json.dumps({'consumer_key': 'XXXX', 'code': cur_auth})
resp = requests.post(url, headers=headers, data=data)
json_resp = resp.json()
access_token = json_resp['access_token']
username = json_resp['username']
session['access_token']=access_token
session['username']=username
access_resp = {'access': access_token, 'user': username}
return jsonify(access_resp)
但是当我尝试将其转换为邮递员请求时,我无法真正理解 consumer_key
request_token
和 code
之类的某些内容是从哪里定义的。
我目前通过此设置收到 400 个错误的请求:
consumer_key
在 Postman 的客户端机密字段中的位置,以及
https://[hostname].com/v3/oauth/request
在 Postman 的 auth 字段中并且
https://getpocket.com/v3/oauth/authorize
位于 Postman 的访问令牌 URL 字段中。