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

APP-3031: make auth0.go generic to auth providers #216

Merged
merged 16 commits into from
Dec 19, 2023
Merged

APP-3031: make auth0.go generic to auth providers #216

merged 16 commits into from
Dec 19, 2023

Conversation

ohEmily
Copy link
Member

@ohEmily ohEmily commented Oct 25, 2023

APP-3031

(app PR that incorporates these changes)

Tiny PR that I believe (🤞) includes all the changes needed to auth0.go to make it so that we can cutover the app backend to FusionAuth without any further goutils changes.

I didn't rename auth0.go because it'll destroy the version history on this file if I do a squash and merge (only thing enabled for our repo afaik).

Tested that auth still works in app if I:
0) [local setup] add replace go.viam.com/utils => ../goutils and then go mod tidy

  1. replace uses of Auth0Config with AuthProviderConfig in 2 places in server/server.go
diff --git a/server/server.go b/server/server.go
index 9b8a5643..29d00820 100644
--- a/server/server.go
+++ b/server/server.go
@@ -299,7 +299,7 @@ type simpleServer struct {
 	unauthenticatedMux    *goji.Mux
 	grpcServer            rpc.Server
 	auth0State            io.Closer
-	auth0Config           uweb.Auth0Config
+	auth0Config           uweb.AuthProviderConfig
 	webTokenKeyProvider   jwks.KeyProvider
 	jWKSKeyProvider       rpc.TokenVerificationKeyProvider
 	sessions              *uweb.SessionManager

and

@@ -640,7 +640,7 @@ func (ss *simpleServer) setupDependencies(ctx context.Context) error {
 		return errors.Wrap(err, "error unmarshaling auth0 data")
 	}

-	ss.auth0Config = uweb.Auth0Config{
+	ss.auth0Config = uweb.AuthProviderConfig{
 		Domain:     m["domain"],
 		ClientID:   m["clientId"],
 		Secret:     m["secret"],

I'll update goutils in app with the changes above once this is ready to merge.

@viambot viambot added the safe to test Mark as safe to test label Oct 25, 2023
@ohEmily ohEmily requested a review from mcous October 25, 2023 19:24
@mcous mcous requested a review from michaellee1019 October 25, 2023 20:28
@mcous
Copy link
Member

mcous commented Oct 25, 2023

Bringing in the council of Michaels on this one

@viambot viambot removed the safe to test Mark as safe to test label Oct 25, 2023
@ohEmily
Copy link
Member Author

ohEmily commented Oct 25, 2023

One thing I'm not clear on is whether I broke the automatic call to Close() by futzing around with utilization of the io.Closer interface. Any ideas? Could produce some resource leaks.

@viambot viambot added the safe to test Mark as safe to test label Oct 25, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Oct 26, 2023
Copy link
Member

@michaellee1019 michaellee1019 left a comment

Choose a reason for hiding this comment

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

LGTM, some naming suggestions.

@@ -23,30 +23,43 @@ import (
"go.viam.com/utils"
)

// Auth0Config config for auth0.
type Auth0Config struct {
// AuthProviderConfig config options with constants that will probably need to be manually configured after
Copy link
Member

Choose a reason for hiding this comment

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

[nit] consider renaming this file to oidc.go?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to rename as part of this PR as it would destroy the commit history on the squash and merge. I think I should do a git mv as a follow up

Copy link
Member

Choose a reason for hiding this comment

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

Fine with me!

web/auth0.go Outdated Show resolved Hide resolved
mcous
mcous previously approved these changes Oct 30, 2023
Copy link
Member

@mcous mcous left a comment

Choose a reason for hiding this comment

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

LGTM

@michaellee1019
Copy link
Member

One thing I'm not clear on is whether I broke the automatic call to Close() by futzing around with utilization of the io.Closer interface. Any ideas? Could produce some resource leaks.

As long as the app side still calls Close() like it does here: https://github.com/viamrobotics/app/blob/main/server/server.go#L1691, then I don't think there is anything to be concerned about. Its just refactoring and the Close call will be the same.

@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 3, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 3, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 3, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 3, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 13, 2023
@ohEmily
Copy link
Member Author

ohEmily commented Nov 13, 2023

Finally gearing up to merge this since we moved forward the testing and doesn't look like we'll need more app changes?

@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 17, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 17, 2023
@mcous mcous dismissed their stale review November 20, 2023 16:13

Dismissing due to ongoing changes, will re-review when ready

@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Dec 1, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Dec 4, 2023
web/auth0.go Outdated
Comment on lines 234 to 242
// http.SetCookie(w, &http.Cookie{
// Name: h.redirectStateCookieName,
// Value: "",
// Path: "/",
// MaxAge: -1,
// Secure: r.TLS != nil,
// SameSite: http.SameSiteLaxMode,
// HttpOnly: true,
// })
Copy link
Member Author

@ohEmily ohEmily Dec 18, 2023

Choose a reason for hiding this comment

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

[q] @DTCurrie, so this should be turned off for FusionAuth only? Or for both Auth0 and FusionAuth?

Comment on lines +285 to +313
http.SetCookie(w, &http.Cookie{
Name: "viam.auth.token",
Value: token.AccessToken,
Path: "/",
Expires: token.Expiry,
Secure: r.TLS != nil,
SameSite: http.SameSiteLaxMode,
HttpOnly: true,
})

http.SetCookie(w, &http.Cookie{
Name: "viam.auth.refresh",
Value: token.RefreshToken,
Path: "/",
Expires: token.Expiry,
Secure: r.TLS != nil,
SameSite: http.SameSiteLaxMode,
HttpOnly: true,
})

http.SetCookie(w, &http.Cookie{
Name: "viam.auth.expiry",
Value: token.Expiry.Format(time.RFC3339),
Path: "/",
Expires: token.Expiry,
Secure: r.TLS != nil,
SameSite: http.SameSiteLaxMode,
HttpOnly: true,
})
Copy link
Member Author

Choose a reason for hiding this comment

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

@DTCurrie same here -- is there any harm in this being sent for Auth0 as well as FusionAuth? Trying to split this out into different auth providers.

Copy link
Member

Choose a reason for hiding this comment

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

I didn’t actually comment out that first cookie originally, but so don’t think there is any harm in uncommenting it our now. It shouldn’t interfere with what I added.

The changes I made in app don’t really care about auth0 or fusion auth, so the added logic should conceivably work for both. Basically we set temporary cookies with the access token and it’s expiry, then on the front end we call the new token endpoint I added to return those values and clear the temp cookies. Then the front end caches those in local storage and uses them from there. If the expiry time has passed, it sends the user to log back in.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks for the lightning fast response!

@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Dec 18, 2023
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Dec 19, 2023
@ohEmily ohEmily merged commit da61878 into main Dec 19, 2023
7 checks passed
@ohEmily ohEmily deleted the APP-3031 branch December 19, 2023 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test Mark as safe to test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants