-
Notifications
You must be signed in to change notification settings - Fork 18
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
Integrate restaf / restaflib with CSA #6
Comments
Nik:
Cheers... |
Ok, so to answer the URL question - there is a property within the H54S adapter instance which you can read if it's explicitly set, something like hostUrl, but we leave that as blank nowadays as our apps are typically served from the same domain as the APIs. If you need to set a server URL explicitly in your code you can pull it from window.location, but assume that our apps are always served from behind the same reverse proxy as the APIs you want to talk to. On the flow question, I think the answer is 'yes', but possibly not a simple one. I've seen a couple of different definitions of the auth code flow for javascript webapps within the Viya docs, so I guess it's a good idea to write down how our auth mechanism works and fits in within those definitions. Sorry about the wall of text, but I figure it's worth doing - if it makes sense we can probably stick it in the Wiki. So like I said, short answer is yes - the auth flow in question is the Authorization Code flow. But it's also no, as I don't think our apps 'use' that flow as such. We are just a WebAuth session-based client to the OAuth clients (sas.identities, sas.files, sas.folders, sas.casManagement, sas.SASJobExecution, etc.). I think it is the idea described in the third paragraph here (from https://tools.ietf.org/html/draft-ietf-oauth-browser-based-apps-06):
Our apps are a common-domain deployment that depend on built-in browser-based security mechanisms - i.e. those HTTP-only cookies that maintain a webauth session with the actual OAuth clients. They use cookies that our javascript code can never actually read (as described above, the SAS cookies are HTTP-only and served from the same domain, scoped to the URIs of the individual microservices). The text above suggests that this mechanism is more secure than using OAuth, and it comes with the added bonus of zero configuration from the SAS side. The best description I've ever read of this is the Authorization Code flow in Mike Roda's paper from 2018 (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/1737-2018.pdf). In this context, we are just the visual application running in the browser:
Now, this makes things a bit more interesting from a library implementation perspective. Because we are just the dumb browser useragent javascript webapp that has no visibility of the validity of session cookies the browser currently holds for any of our API endpoints, we need a mechanism that handles the ajax redirects to SASLogon if and when we need to reauthenticate for an API request, and a way of handling any resulting HTTP 449 responses (as described in the paper excerpt above). The way we have always handled this with our adapter, for both v9 and Viya, is as follows: Our adapter doesn't expect the developer to implement an explicit 'lets authenticate' step. Instead developers implement all their API requests using our managedRequest wrapper, which allows them to simply assume that request will eventually be satisfied, even if it is redirected to SASLogon. That managedRequest xhr wrapper wraps those requests to the APIs, and then handles the request for user authentication if it detects that a response came back as a SASLogon redirect. In practice, even though there's no 'let's authenticate' step, users do tend to see the logon screen as soon as they start the app because as soon as the app starts it tries to fetch the userAvatar from the /identities service, which then gets redirected to SASLogon and triggers that Login routine (unless the user is logged in to another SAS app in another tab in which case they don't have to do anything). When a request is redirected to SASLogon in the background, such as when a session expires, the app locks the UI and prompts the user for a password. The callback for the original request that failed with a redirect to SASLogon gets pushed to a stack, and is resumed/retried and satisfied once we have a newly authenticated session. This is how it works both on SAS v9 and on Viya, for both job calls to the JES and for any API calls using the 'managedRequest'. So what does this mean for restaf integration In the same way you use axios to talk to the APIs, we use our adapter's That aside, I think initially you should just be able to work with the browser session that the app obtains on startup? As long as you have a way of turning off the authorisation headers in the requests so that they don't override the session-based auth that's already in place. This response is so long winded and repetitive. I might edit it later. But I hope it makes sense. |
This is a placeholder to track integration of @devaKumaraswamy's excellent restaf + restaflib into CSA, as an enhancement to our own managedRequest API access mechanism.
Looking at the authentication options it should be possible to configure axios with an intereceptor to pause requests while re-authentication happens, and I quite like the idea of moving h54s to axios in general for the next version - it does a lot of things elegantly which we implemented from scratch within h54s (because axios didn't exist at the time).
We need to think about how we best do it - whether to just include restaf here as a branch that we integrate with the login screen and keep the current auth + keepalive mechanisms, or wait until h54s v3 where we can share axios with restaf. Just putting this out there for now.
The text was updated successfully, but these errors were encountered: