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

Bypass Google auth when Okta is configured #144

Merged
merged 28 commits into from
Apr 27, 2023
Merged

Conversation

jfreda
Copy link
Collaborator

@jfreda jfreda commented Apr 18, 2023

This PR adds functionality to bypass Google auth when Okta is configured. To do this, a GET method was added for the /api/v1/me API with a response that mimics Google's userinfo API, which we previously used to get a user's profile photo and name. Also, now that #132 was merged, this removes the code for using the Google Drive application data for storing recently viewed docs.

Breaking changes

  • The Admin SDK API now needs to be enabled.
  • New required aws_region configuration option for the okta block

web/web.go Outdated Show resolved Hide resolved
web/web.go Outdated Show resolved Hide resolved
@jfreda jfreda marked this pull request as ready for review April 19, 2023 19:50
@jfreda jfreda requested a review from a team as a code owner April 19, 2023 19:50
Copy link
Contributor

@anubhavmishra anubhavmishra left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Contributor

@jeffdaley jeffdaley left a comment

Choose a reason for hiding this comment

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

Looks good. I have some questions but it seems like we're close.

We seem light on front-end tests given the number of changes. Depending on your answers, let's stub some todos if not get a few more tests in here. I can help with that of course.

Comment on lines 108 to 114
// Update recently viewed docs for the dashboard route.
try {
await this.recentDocs.fetchAll.perform();
} catch (e) {
console.error("error updating recently viewed docs", e);
throw e;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem important here. What if you remove it and defer that load for when the user is actually visiting the dashboard? Otherwise I'd call it with void instead of try { await } so it doesn't hold up loading other stuff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was just minimizing changes, and when I fully removed this, the recently viewed docs weren't being updated in the dashboard until I refreshed the page. I just tried moving this to the dashboard route though and it seems to work, so I can move it there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines +84 to +90
{{#if this.showSignOut}}
<dd.Interactive
data-test-user-menu-item="sign-out"
{{on "click" this.invalidateSession}}
@text="Sign out"
/>
{{/if}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we removing the logout button? What happens if I skipGoogleAuth and try to invalidateSession?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't do anything because there's no Ember Simple Auth session to invalidate when we bypass Google auth.

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 have it invalidate with Okta instead? I assume users will still want to sign out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our supported Okta configuration enforces Okta auth at the load balancer level so there's not going to be a way to sign out unless the user signs out of their Okta session (which will be in Okta, not Hermes).

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 change our supported configuration to allow logout? 😬 I'd really like to keep the log out button. "As a user I want to log out."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We chatted about this offline, but I think I found a way to do this and it'll be implemented in another PR soon!

* and if it is, transitions to the specified route
*/
this.session.prohibitAuthentication("/");
if (!this.configSvc.config.skip_google_auth) {
this.session.prohibitAuthentication("/");
Copy link
Contributor

@jeffdaley jeffdaley Apr 19, 2023

Choose a reason for hiding this comment

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

What happens if we remove this if statement and run prohibitAuthentication under skipGoogleAuth conditions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like it's the same behavior. I think I forgot what this method actually does - I can revert this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's supposed to redirect you to / if you're authenticated with Ember Simple Auth

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, actually I guess we should probably just redirect right away from this route if we're bypassing Google auth... Because users could still have this URL saved and it won't be relevant without Google auth.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

8d11b85 implements this ^

*/
void this.session.pollForExpiredAuth.perform();
if (!this.configSvc.config.skip_google_auth) {
void this.session.pollForExpiredAuth.perform();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does skipping Google auth negate the need to poll for expiredAuth?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good q, 2 things here:

  • I still need to do some more testing on the app behavior when Okta auth expires; it might still be useful to do this polling if the user isn't immediately redirected to log in to Okta.
  • Currently pollForExpiredAuth is (understandably) Google-centric so I think we'll want to at least skip this until that either becomes neutral to the auth provider or has an Okta option built in too (assuming that we'll want to poll when skipping Google auth; still need to test).

Copy link
Contributor

Choose a reason for hiding this comment

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

it might still be useful to do this polling if the user isn't immediately redirected to log in to Okta

Yeah, I'd like to maintain our existing behavior where we detect passive logouts: If your token expires in the background, we should block [Okta]'s immediate-redirect function to show a gentler "reauathenticate" message.

Your change makes sense and its good to know you're planning to test further.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Re-enabled polling auth for Okta in this commit: 23635e6

@jfreda jfreda added the breaking changes PR contains breaking changes label Apr 27, 2023
@jfreda jfreda merged commit ebed57e into main Apr 27, 2023
@jfreda jfreda deleted the jfreda/bypass-google-auth branch April 27, 2023 21:01
anuragprafulla pushed a commit to razorpay/hermes that referenced this pull request Jun 27, 2023
* Make people directory search read mask configurable in helper function

* Add GET method for /api/v1/me endpoint

* Bypass Google auth when Okta is configured

* Only show Sign Out when using Google auth

* s/bypass/skip

* Update recently-viewed-docs-test.ts

* Update Mirage `/me` reference

* Update Mirage document timestamp; Fix test

* Add note that Okta is instead of Google OAuth

* Format config

* Redirect right away from the authenticate route if skipping Google auth

* Fetch recently viewed docs in the dashboard route instead of document

* Add Admin service back

* Add GetUser helper

* Hack around bug with People API not returning names

* Set the ALB auth cookie to an expired time when the token is invalid

* Poll auth expiration when using Okta as well

* Handle Okta redirect errors from fetch

* Authorize Okta request using OIDC data header and verifying claims instead of verifying the access token

* Update OIDC data format

* Decode JSON into an interface

* Handle AWS's JWTs that include padding

* Use public key type for Parse key function

* Use string type for preferred_username and log values on error

* Don't compare preferred_username claim to OIDC identity header

* Update flash message title

* Add Admin SDK API to list of APIs that need to be enabled

---------

Co-authored-by: Jeff Daley <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes PR contains breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants