trinodb / trinodb/trino-python-client
Custom cache for oauth2 tokens
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 439
- Forks
- 206
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I have a flask app, which uses trino python client to query the data from my trino servers and I have enabled oatuh2 authentication against my azure active directory, currently, the token is caching per host, I need to have it cached per user who authenticates on the front end of my web application. I have implemented my custom cache below and it is working as per my use case, but I prefer not to change any private properties as it's not the best practice.
from flask import session
class _CustomCache(_OAuth2TokenCache):
"""
In-memory token cache implementation. The token is stored per user.
"""
def __init__(self):
self._cache = {}
def get_token_from_cache(self, host: str) -> Optional[str]:
userName=session['user']
return self._cache.get(userName)
def store_token_to_cache(self, host: str, token: str) -> None:
userName=session['user']
self._cache[userName] = token
temp=OAuth2Authentication()
temp._bearer._token_cache=_CustomCache()
conn=connect(
host='******',
port=443,
auth=temp,
http_scheme="https"
)
cursor=conn.cursor()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing OAuth2Authentication, _OAuth2TokenCache, and the _bearer._token_cache assignment shown in the report. Confirm how the current host-keyed cache is reached, then determine the supported configuration boundary for user-scoped caching without private properties. Done should include coverage showing separate users receive the correct cached tokens.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, flask, python
- Domain
- authentication
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100