Skip to content

Commit 83fa5ab

Browse files
committed
added access token verification to refresh token endpoint
1 parent 68690f4 commit 83fa5ab

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sample_endpoint/example_server.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def on_get(self, req, resp):
2424
payload = {"client_id": CLIENT_ID,
2525
"client_secret": SECRET}
2626

27+
2728
# Copy out all values from the request
2829
for k, v in req.params.items():
2930
payload[k] = v
@@ -52,6 +53,28 @@ def on_post(self, req, resp):
5253
payload = {"client_id": CLIENT_ID, "client_secret": SECRET}
5354
payload["grant_type"] = "refresh_token"
5455

56+
auth_header = req.get_header('Authorization')
57+
if auth_header:
58+
auth_header = auth_header.strip()
59+
60+
if not auth_header or 'Bearer:' not in auth_header:
61+
err_blob = {'error': 'Invalid or missing bearer token'}
62+
resp.body = json.dumps(err_blob)
63+
resp.status = falcon.HTTP_405
64+
return
65+
66+
access_token = auth_header.split("Bearer:")[-1].strip()
67+
fxa_resp = requests.post("https://oauth-stable.dev.lcip.org/v1/verify",
68+
data=json.dumps({"token": access_token}))
69+
70+
if fxa_resp.status_code != 200:
71+
print "Invalid access token. Verify response: " + str(fxa_resp.status)
72+
return
73+
else:
74+
print "Existing access token is valid!"
75+
else:
76+
print "No auth header found!"
77+
5578
# Copy out all values from the request
5679
body = req.stream.read()
5780
print "POST data received: " + body

0 commit comments

Comments
 (0)