-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Superset: Fetch superuser/staff status from OAuth #42
Superset: Fetch superuser/staff status from OAuth #42
Comments
FYI @bmtcril |
We may be able to fix this one in the same changes as well: openedx-unsupported/tutor-contrib-superset#11 |
Is there a defined starting point for this issue? |
Hi @Ian2012 thanks for taking on this task! I don't enough about OAuth2 and JWT to advise you specifically here, but maybe these pointers will help?
|
@pomegranited Seems like to get a JWT token, we need to authenticate with google or facebook, or send the username and password: |
@Ian2012 I'm hoping that comment is out of date.. Have you tried using the
Or even just |
Hi there @pomegranited: I ran some tests following your suggestions, thank you so much! Here are our findings: We first tried |
We tried other stuff, like getting the JWT cookie set during the LMS login: |
@mariajgrimaldi Hmm.. that's probably an ok workaround if need be.. What do you think, @bmtcril ? I dug around and didn't find anything specifically useful to this cause, but I found something kind of related: With python social_auth, there's also a Flask-AppBuilder shows an example of its equivalent using OAuth: https://github.com/dpgaspar/Flask-AppBuilder/blob/master/docs/security.rst#authentication-oauth It shows example configs for various 3rd-party oauth providers , with an example of overwriting the |
@pomegranited: this is kind of a brain dump. Here we go: About JWT tokens and scopesThis is how I understand the current mechanism works (roughly), let me know if I got something wrong:
Now, if I'm right, the token generated doesn't contain information about the user. So, we could configure other scopes and still our token would have the same amount of data, right? Now, If we were using JWT instead, we could modify the scopes getting that way more info about the user associated with the token, as explained here. This mechanism reminds me a bit of the Studio SSO, which roughly works as follows:
Studio uses the auth-backend library to implement the callback we specified in the redirect URI field. Calling Authorization view from the edx-oauth2 backend based on Social Core: https://github.com/python-social-auth/social-core/blob/master/social_core/backends/oauth.py#L359 -- here, self.data contains the query params sent by the LMS which contain the code parameter. Authorization view from flask app builder: https://github.com/dpgaspar/Flask-AppBuilder/blob/master/flask_appbuilder/security/views.py#L650 -- here, the code parameter seems to get ignored entirely So we can't call the LMS and generate a JWT like Studio does without that code. I'm not sure if we could do a workaround to get the authorization code to generate a JWT token or even generate it using other configurations. I'll be testing some more this token generation 🤔 About flask app builder authThe pattern I've found in some examples for getting the user's information is calling an API hosted by the IdP, like when they do |
Hi @mariajgrimaldi , thank you for summarising what you've learned about OAuth and JWT, that really helps me understand! I've CC'd you on this thread with @robrap on Slack -- he's suggesting there's a way to request the token directly as JWT, bypassing Bearer tokens entirely.
Lol yeah, agreed. Please disregard my suggestion about changing how we get this info :) |
@pomegranited: I responded on Slack, but if it makes sense to move the conversation to this PR, please do that. Thanks. UPDATE: I didn't see the above comment yet about JWTs, and am reading it now. |
@mariajgrimaldi: I wonder if you need the equivalent of https://github.com/openedx/edx-platform/blob/f0a9ef21613a780e4c7975de47375fe7f21e3710/openedx/core/djangoapps/oauth_dispatch/views.py#L115C1-L116 in the |
@robrap: I'll research a bit more of that! I'll let you know |
I tried to override the
It actually worked! We got the JWT during the user authentication. But we hit a wall afterward: Authlib oauth2 backend only supports Bearer tokens: https://github.com/lepture/authlib/blob/master/authlib/integrations/requests_client/oauth2_session.py#L16-L17 I posted a question on Stack overflow explaining what I was trying to do: https://stackoverflow.com/questions/76274928/unsupported-jwt-token-type-using-authlib. I was going to open an issue on the repo, but they suggest to ask questions on there. |
If this is interacting with our APIs, at this time, we require the authorization header to use |
Well, we kind of did it: openedx-unsupported/tutor-contrib-superset#40. I followed Robert's suggestion to get there:
This is currently looking incredibly hacky, but it's working: I'm gonna do some other stuff and take a look later with fresher eyes. |
@mariajgrimaldi: Congrats on getting it working. If we used "Bearer" in the Authorization header, rather than "JWT", but included the JWT as the token, would that be the non-hacky version? I think that would all be part of the BearerAuthentication DEPR: openedx/edx-drf-extensions#284. FYI: @feanil: Since you are looking into authentication clean-up work and issues related to current state. |
There was no need to modify the OAuthView class to accept the JWT token type. Here is a new implementation of this working: openedx-unsupported/tutor-contrib-superset#44 with some refactoring and fixes |
assign me |
Currently, the Open edX SSO Security Manager installed by https://github.com/openedx/tutor-contrib-superset queries the Open edX MySQL database to determine if a user is a superuser or global staff, in order to determine their roles and permissions in Superset.
This information should be gleaned from OAuth data instead.
e.g. the openedx:auth_backends/backends.py decodes this information from the JWT access_token. Superset has only an OAuth2 bearer token, but we should be able to convert this to JWT (ref).
cf openedx-unsupported/tutor-contrib-superset#6 (comment)
The text was updated successfully, but these errors were encountered: