-
Notifications
You must be signed in to change notification settings - Fork 30
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
Investigation: do we still need Panoptes JavaScript Client (PJC)? #5995
Comments
Roger wrote some docs for The important thing to remember about those clients is that they are stateful. When you |
Also, if it's useful at all: Panoptes access tokens are good for two hours, so make sure you have a refreshed token before making a credentialled request. AFAIK Panoptes refresh tokens never expire (maybe double-check with the backend team about this) but Panoptes session cookies expire after two weeks of inactivity. You can check the session cookie lifetime in browser dev tools. Frontend auth for a typical session looks something like this:
Panoptes.js doesn't have an auth client at all, just some helper functions that can decode an access token, which is a JWT, and return the user and permission scopes that are encoded inside. You still need to use an OAuth client, of some sort, in order to get that token from Panoptes OAuth. |
If you're new to OAuth, I highly recommend watching Kim Maida's The Art of Authentication before jumping into any Panoptes auth code. That talk really clarified Panoptes OAuth for me. Refresh Tokens: What are they and when to use them is also a useful read. |
Zooniverse Classrooms use |
Panoptes auth uses access tokens to encode both user info (identity) and scopes (access permissions.) That's not really recommended any more. A modern approach, still using OAuth, would be to put user identities into ID tokens and have the access token only responsible for limiting access to protected resources. Maybe something to bear in mind for things like Zooniverse user groups and Zooniverse user certificates? The whole Panoptes auth implementation in the frontend is something like ten years old now.
https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/ |
@mcbouslog this issue, from 2018, raises the same issues as you are interested in, I think, so could be worth reading. Specifically, there's a bunch of repeated code in the JS API client for token storage and management (both refresh tokens and access tokens):
There's also an open request to support the authorization code flow (for an old PRN server app), which would also be useful now that password grant is disallowed and implicit grant is discouraged. The Python API client already supports authorization codes for server-side authentication eg. I use an authorization code here to build new subjects for the SLSN project. As a user of both the JS and Python API clients, it would be useful to have parity between them. |
Thank you @eatyourgreens ! This comment and links, as well as related Slack posts are very helpful. It's looking the panoptes-javascript-client auths at minimum and likely auth in general could use an overhaul. |
Also worth noting that none of the code discussed here uses See #317 |
Also noting that the Next.js app router expects data-fetching to use |
Linking a couple of relevant convos for future consideration of PJC in our frontend: Superagent and SWR: #6117 (comment) Talk board visibility to admins: https://zooniverse.slack.com/archives/C06DCM0V9/p1720463383130629 |
Investigation
Question: do we still need the old panoptes-javascript-client (aka PJC) in FEM? If so, why, and where?
Context:
Additional reading (for nerds):
Current PJC Use
The following indicates where PJC is still used in the FEM code, as of 21 Mar 2024.
app-content-pages
auth.signOut()
is used in PageHeaderapp-project
auth.signOut()
is used in PageHeaderauth.checkBearerToken()
is used in usePanoptesAuth.jsauth.checkBearerToken()
andauth.checkCurrent()
are used in usePanoptesUser.jssugarClient.subscribeTo()/unsubscribeFrom()
are used in useSugarProject.jsauth
is passed down to the Classifier, on ClassifierWrapper.jsauth.checkBearerToken()
is used in checkRetiredStatus.jsauth.checkBearerToken()
is used in Collections.jsauth.checkBearerToken()
is used in Recents.jsauth.checkBearerToken()
and sugarClient are used in Notifications.jsauth.checkBearerToken()
is used in UserProjectPreferences.jsauth.checkBearerToken()
is used in YourStats.js(You know, I think I'm starting to detect a pattern here.)
app-root
auth
is passed down as the "authClient" in the Next.js pages: GroupPage, MyGroupsPage, UserStatsPage.auth.signOut()
is used in PageHeaderlib-async-states: no PJC here
lib-classifier
oauth
is used in the dev server(authClient).checkCurrent()
is used in RootStore.js(authClient).checkBearerToken()
is used in models/Annotation.js(authClient).checkBearerToken()
is used in utils/getBearerToken.jslib-grommet-theme: no PJC here
lib-panoptes-js: no PJC here, obviously. This is Panoptes.js!
lib-react-components
auth.signIn()
is used in LoginFormContainer.jsauth.register()
is used in RegisterFormContainer.jsauth.checkBearerToken()
is used in fetchPanoptesUser.jsauth.checkCurrent()
,auth.listen('change')
, andauth.stopListening('change')
are used in usePanoptesUser.jsauth.checkCurrent()
andauth.checkBearerToken()
are used in useUnreadMessages.jsauth.checkCurrent()
andauth.checkBearerToken()
are used in useUnreadNotifications.jslib-user
oauth
is used in the dev server.auth.checkCurrent()
,auth.listen('change')
, andauth.stopListening('change')
are used in the dev server(authClient).checkBearerToken()
is used in utils/getBearerToken.js.tools-standard: no PJC here
Analysis
The following auth functions exist in PJC, but don't (yet?) exist in Panoptes.js. See PJC's auth.js for the full code.
auth.checkCurrent()
: ⭐ used in multiple instancesauth.checkBearerToken()
: ⭐ used in multiple instancesauth.signIn()
andauth.signOut()
: only used on the sign in/out components (the page headers)auth.register()
: only used in the register user formauth.listen('change')
andauth.stopListening('change')
: only used in lib-react-components to listen for when the user logs in or out.Compare with Panoptes.js's auth.js code, which only has...
verify()
decodeJWT()
oauth
is only directly used as "authClient"s passed down to packages in dev servers. Mark's work with lib-user seems to indicate we may be able to replace PJC'soauth
with PJC'sauth
.I have no idea what to make of the
sugarClient
. 🤷♂️❗ We now present Shaun arguing with himself about oAuth:
*.zooniverse.org
domain name. Newer CFEs such as Community Catalog do have*.zooniverse.org
domain names, so they can use PJC'sauth
*.zooniverse.org
a domain name or a hostname? Should the sentence be "Community Catalog is a subdomain parked under the .zooniverse.org domain"?Status
Main investigation complete. Awaiting discussion, to plan further steps for Panoptes.js.
The text was updated successfully, but these errors were encountered: