converting python oauth to postman request

Viewed 280

I am trying to convert successful python (flask) OAuth 2.0 authentication / api request into Postman.

My current process is:

From the front end, I hit an /auth endpoint in python using fetch:

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`;
    });

The backend flask auth endpoint looks like this:

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)

The access endpoint takes that auth code to get the token

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)

But when I try to translate this into a postman request, I can't really understand where some of the things like the consumer_key request_token and code get defined.

I'm currently getting a 400 bad request with this setup:

enter image description here

where the consumer_key is in Postman's client secret field, and where

https://[hostname].com/v3/oauth/request is in Postman's auth field and https://getpocket.com/v3/oauth/authorize is in Postman's access token url field.

0 Answers
Related