Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

fix: fetch superset info from oauth #44

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

Ian2012
Copy link
Contributor

@Ian2012 Ian2012 commented May 29, 2023

Description

This PR is an reimplementation of #40

This PR updates the oauth implementation to get a JWT to get the user information.

Have in mind that edx-platform doesn't store the fields first name and last name, that's why we need to provide the name base on the full name field. In the screenshot below, the user Cristhian G was logged in with the new implementation.
image

Also, the current implementation doesn't update the name after following logins.

This PR:

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label May 29, 2023
@openedx-webhooks
Copy link

Thanks for the pull request, @Ian2012! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

Comment on lines 60 to 31
def add_bearer_jwt_token(token, uri, headers, body, placement='header'):
if placement in ('uri', 'url', 'query'):
uri = add_to_uri(token, uri)
elif placement in ('header', 'headers'):
headers = add_to_headers(token, headers)
elif placement == 'body':
body = add_to_body(token, body)
return uri, headers, body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we just need to modify the add_to_headers utility method, I think we could use the add_to_body and add_to_uri that authlib implements. Don't you think?

'last_name': '',
'id': user_profile['preferred_username'],
'username': user_profile['preferred_username'],
'first_name': user_profile['family_name'] if user_profile['family_name'] else user_profile['name'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does user_profile always have the family_name and name entries?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have it backward:

        'name': name,
        'family_name': user.last_name,
        'given_name': user.first_name,
        'administrator': user.is_staff,
        'superuser': user.is_superuser,

From: https://github.com/openedx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/jwt.py#L265

@mariajgrimaldi
Copy link
Contributor

I tested this and it's working as expected. Just one quick comment, the first name and last name are recorded after registering, if the user already exists, then it's not saved again. I didn't know that. Maybe there's a configuration for updating existing users -- maybe it's not even needed since this project is brand new.

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking fantastic, and really close to being done! Great work @Ian2012 and @mariajgrimaldi , this is so much cleaner.

Please see comments inline.

@itsjeyd itsjeyd added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label May 31, 2023
@Ian2012 Ian2012 force-pushed the cag/jwt-bearer-token branch 8 times, most recently from c1dacd6 to 105a38c Compare June 1, 2023 18:50
Comment on lines 1 to 9
from collections import namedtuple
import logging
import MySQLdb

from flask import current_app, session

from superset.security import SupersetSecurityManager
from superset.utils.memoized import memoized

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we run isort?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Ian2012 Ian2012 force-pushed the cag/jwt-bearer-token branch 3 times, most recently from 682e5d2 to 6931a5b Compare June 2, 2023 15:24
Copy link
Contributor

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this deployed in one of our installations, and it's working nicely! Thank you for the improvement 🥳

Comment on lines 146 to 142
UserAccess = namedtuple(
"UserAccess", ["username", "is_superuser", "is_staff"]
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above, we don't need this UserAccess tuple (or the namedtuple import) anymore:

Suggested change
UserAccess = namedtuple(
"UserAccess", ["username", "is_superuser", "is_staff"]
)

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This works perfectly @Ian2012 ! Couple of minor nits noted below, but it's good to merge when they're resolved.

  • I tested this on a fresh Tutor dev deployment.
  • I read through the code
  • I checked for accessibility issues N/A
  • Includes documentation N/A

@Ian2012
Copy link
Contributor Author

Ian2012 commented Jun 5, 2023

@pomegranited thanks for the review, it's corrected now

@bmtcril bmtcril merged commit ccd9fec into openedx-unsupported:main Jun 5, 2023
@openedx-webhooks
Copy link

@Ian2012 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@itsjeyd itsjeyd removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Jun 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: SSO'd users have no name in Superset Superset: Fetch superuser/staff status from OAuth
6 participants