Using python how does one access properties in the existing securityContext if the check_sql_auth function is being called for a reauth/change user flow?
- Dominant language
- Rust
- Stars
- 20.8k
- Forks
- 2.1k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 181
Description
**How to use the securityContext dictionary when it is not a check_sql_auth function parameter?**
The documentation provides the following information:
`check_sql_auth implementation should gracefully handle missing password field to handle change user and re-authentication flows. `
Unfortunately, I could find no examples that illustrate how to accomplish gracefully handling the re-auth/change user flow. I tried accessing the securityContext from the global **COMPILE_CONTEXT** and tried **SECURITY_CONTEXT** without any luck.
Using the example in the docs, if I set something in the securityContext dictionary nested in the dictionary check_sql_auth returns, how do I access those **securityContext** dictionary properties within a future check_sql_auth invocation? Below is my current **check_sql_auth** implementation. In practical terms, how do I check the **securityContext["auth"]** dictionary value on a reauth/change user flow?
```
from cube import config
@config('check_sql_auth')
def check_sql_auth(req: dict, user_name: str, password: str) -> dict:
# Verify user_name and password, if password is not
# supplied auth has already occurred. Check user name is the same.
if not password:
if user_name == "redacted":
authenticated = True
else:
authenticated = False
else:
authenticated = ( user_name == "redacted" and password == "redacted" )
if authenticated:
return {
'password': password,
'securityContext': {
# You can user-related attributes to the security context
'auth': True
}
}
raise Exception('Incorrect user name ' + user_name + ' or password.')
```
Contributor guide
Assessment
This issue has not been assessed yet.