Skip to content
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

Add support for round-tripping the user through Unified Ecommerce on login #2515

Merged
merged 4 commits into from
Jan 24, 2025

Conversation

jkachel
Copy link
Contributor

@jkachel jkachel commented Jan 22, 2025

What are the relevant tickets?

mitodl/hq#6520

Description (What does it do?)

After login, this throws the user to the Unified Ecommerce session start endpoint, which will start up a session for the user there and then send them back to MITx Online. This ensures the user can interact with the cart while in MITx Online (to get cart status, add items, etc.).

How can this be tested?

The code for this is feature flagged out. Ensure enable_unified_ecommerce is configured in PostHog to test this. It needs to be Enabled. (Additionally, you should have your MITx Online setup configured to use PostHog, and ideally a project that you control rather than one of the regular OL ones.)

You'll need a Unified Ecommerce instance set up. Specifically, it will need to be set up and tracking jkachel/6520-add-updates-to-establish-session so you have the other side of the equation (unless mitodl/unified-ecommerce#200 is merged when you test). The instructions for setting up Unified Ecommerce are in the README and README-keycloak files.

In the .env file, optionally set UNIFIED_ECOMMERCE_URL to the URL you have set up for the UE API. The default is `http://ue.odl.local:9080/' - if you've set the hostnames up differently, then you should set this appropriately. Do not set this to the port for the frontend (8072 usually).

In Unified Ecommerce, you should have an Integrated System set up with a slug named "mitxonline". The homepage URL should be set to the root URL for your MITx Online instance.

Ensure you have a Web Inspector pulled up into the Network tab, and enable Preserve Log. Then, log into the system. Once you've entered your password, you should see that you're being thrown to Unified Ecommerce. You'll likely have to log into Keycloak, and then you should be thrown back to MITx Online.

If you start somewhere that redirects you into login (like, from clicking Enroll on a course while logged out), you should be sent back to the proper page.

Note that if you have a Keycloak session already - in other words, you logged into Unified Ecommerce before MITx Online - you won't be prompted to log in again. We don't expose a logout from the UI, but you can log out of Unified Ecommerce by going to http://ue.odl.local:9080/logout. This will destroy your UE session and your Keycloak session, so you'll have a blank slate.

Additional Context

The learner needs a UE session so that they can interact with the API (i.e. get cart status, add things to cart, etc.). Doing this by throwing the user to UE once they've logged into MITx Online seemed like a reasonable way to do this.

Once MITx Online auths through Keycloak, UE will pick up the existing Keycloak session and start its own session up using that. Since these will share the same underlying Keycloak instance, the sessions should all be the same.

The feature flag check happens before the learner logs in, so we will be limited in our ability to conditionally enable the flag. We can limit the flag via the client's IP address, but we should be careful to check/clear these as we're testing because IP addresses often change on consumer-grade Internet connections.

…login

This will ensure they get signed into UE when they log into MITx Online, so they can then get to the cart/etc.

This is feature flagged - ensure "enable_unified_ecommerce" is configured in PostHog to test this. Because this is checked before login, you won't be able to limit this to specific usernames. (You can still limit it somewhat, like to IP address.)

Until MITx Online is set up to use Keycloak for authentication, this will necessarily require you to log into Keycloak too once you've logged into MITx Online. There's no requirement that you log in using the _same_ account. MITx Online will have no idea what your session in UE is.
@jkachel jkachel marked this pull request as ready for review January 23, 2025 15:37
@cp-at-mit cp-at-mit self-assigned this Jan 23, 2025
@jkachel jkachel merged commit 150f316 into main Jan 24, 2025
7 checks passed
@jkachel jkachel deleted the jkachel/6520-add-post-login-redirect-to-ue branch January 24, 2025 21:44
@odlbot odlbot mentioned this pull request Jan 29, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants