mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-09 04:19:32 +00:00
* Use Authorization headers for retrieving token info * Fix flake8 * Adjust token info example * Only accept Authorization headers in test
34 lines
613 B
Python
Executable File
34 lines
613 B
Python
Executable File
#!/usr/bin/env python3
|
|
'''
|
|
Mock OAuth2 token info
|
|
'''
|
|
|
|
import connexion
|
|
from connexion import request
|
|
|
|
# our hardcoded mock "Bearer" access tokens
|
|
TOKENS = {
|
|
'123': 'jdoe',
|
|
'456': 'rms'
|
|
}
|
|
|
|
|
|
def get_tokeninfo() -> dict:
|
|
try:
|
|
_, access_token = request.headers['Authorization'].split()
|
|
except Exception:
|
|
access_token = ''
|
|
|
|
uid = TOKENS.get(access_token)
|
|
|
|
if not uid:
|
|
return 'No such token', 401
|
|
|
|
return {'uid': uid, 'scope': ['uid']}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = connexion.FlaskApp(__name__)
|
|
app.add_api('mock_tokeninfo.yaml')
|
|
app.run(port=7979)
|