将python oauth转换为邮递员请求

时间:2021-04-13 21:25:37

标签: python api flask oauth postman

我正在尝试将成功的 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_tokencode 之类的某些内容是从哪里定义的。

我目前通过此设置收到 400 个错误的请求:

enter image description here

consumer_key 在 Postman 的客户端机密字段中的位置,以及

https://[hostname].com/v3/oauth/request 在 Postman 的 auth 字段中并且 https://getpocket.com/v3/oauth/authorize 位于 Postman 的访问令牌 URL 字段中。

0 个答案:

没有答案