<filename>examples/get-token-example.py
import requests
import json
import time
import jwt

# Get urls.
well_known = requests.get("https://auth.jpace121.net/realms/jpace121-main/.well-known/openid-configuration")
well_known = well_known.json()
auth_url = well_known['device_authorization_endpoint']
token_url = well_known['token_endpoint']

header = {"Content-Type":"application/x-www-form-urlencoded"}
data = {"client_id" : "jpace-mqtt"}

r = requests.post(auth_url, headers=header, data=data)
r_json = r.json()

print("Go to: {} to login.".format(r_json['verification_uri_complete']))

data['grant_type'] = "urn:ietf:params:oauth:grant-type:device_code"
data['device_code'] = r_json['device_code']

for index in range(1, 20):
    r = requests.post(token_url, headers=header, data=data)
    if 'access_token' in r.json():
        break
    time.sleep(r_json['interval'])

public_key = b"-----<KEY>"

#decoded = jwt.decode(r.json()['access_token'], audience=None, options={"verify_signature": False, 'verify_aud': False})
decoded = jwt.decode(r.json()['access_token'], public_key, algorithms=['RS256'])
print('Decoded: {}'.format(decoded))

<filename>examples/get-token-example.py
import requests
import json
import time
import jwt

# Get urls.
well_known = requests.get("https://auth.jpace121.net/realms/jpace121-main/.well-known/openid-configuration")
well_known = well_known.json()
auth_url = well_known['device_authorization_endpoint']
token_url = well_known['token_endpoint']

header = {"Content-Type":"application/x-www-form-urlencoded"}
data = {"client_id" : "jpace-mqtt"}

r = requests.post(auth_url, headers=header, data=data)
r_json = r.json()

print("Go to: {} to login.".format(r_json['verification_uri_complete']))

data['grant_type'] = "urn:ietf:params:oauth:grant-type:device_code"
data['device_code'] = r_json['device_code']

for index in range(1, 20):
    r = requests.post(token_url, headers=header, data=data)
    if 'access_token' in r.json():
        break
    time.sleep(r_json['interval'])

public_key = b"-----<KEY>"

#decoded = jwt.decode(r.json()['access_token'], audience=None, options={"verify_signature": False, 'verify_aud': False})
decoded = jwt.decode(r.json()['access_token'], public_key, algorithms=['RS256'])
print('Decoded: {}'.format(decoded))

# Get urls. #decoded = jwt.decode(r.json()['access_token'], audience=None, options={"verify_signature": False, 'verify_aud': False})