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

Initial SSO chapter #191

Merged
merged 4 commits into from
May 20, 2024
Merged

Initial SSO chapter #191

merged 4 commits into from
May 20, 2024

Conversation

DarkoKukovec
Copy link
Member

@DarkoKukovec DarkoKukovec commented Mar 15, 2023

The goal of this chapter is to explain how to work with auth (right now the focus is on sso).
Once we have libs for this, we could also add more specifics for them.

New chapter PR:
https://github.com/infinum/frontend-handbook-private/pull/76

Copy link
Contributor

@fvoska fvoska left a comment

Choose a reason for hiding this comment

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

Generally this is a good approach, but we should battle-test it a bit with commonly used FE libraries like MSAL which has both React and Angular flavours.

If we are using AD, we will most probably use MSAL and we would have to see how we can use it with BFF and redirect-based flows.

MSAL also has a popup-based flow, but I guess that is out of the question because BFF flow could only work in a redirect-based flow.


#### With server-side rendering

When we're working on an app that might do API calls fro the server (e.g. fetching data for the server-side render), we need to have the token available on the server, which means that the cookie is the only option. In this case, we can use the approach the specification calls ["backend for frontend"](https://www.ietf.org/archive/id/draft-ietf-oauth-browser-based-apps-10.html#section-6.2). In general, that means that our backend is the SSO client and it should create a separate session for our client code:
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, that means that our backend is the SSO client
I would maybe clarify here that by "backend" you mean BFF backend that was mentioned in the previous sentence, and not the "core backend" that BFF connects to

Auth.md Outdated Show resolved Hide resolved
@DarkoKukovec
Copy link
Member Author

DarkoKukovec commented Mar 16, 2023

I'm not convinced MSAL is a good solution:

  1. I don't like having a special case solution for a single provider, especially if we only need the login part
  2. We often work with other providers, so it's not like it's solving most of our problems
  3. Does it have a good SSR support? Looking at the NextJS example, it seems like it's doing everyting on th client?
  4. The point of this chapter: I'm not sure that the MSAL library is handling tokens in the recommended ways - from the looks of it, it is saving them to localStorage, which might be good enough for some cases, but is vulnerable to XSS attacks.

@fvoska
Copy link
Contributor

fvoska commented Mar 16, 2023

Is there some FE lib that we are ok with using for standard OIDC flows?

I can speak for Angular that, if using AD, MSAL makes most sense. For other providers, we can use angular-auth-oidc-client. We used angular-auth-oidc-client on CEERIS and there it was actually done as you describe here. We didn't have BFF explicitly, but our Rails backend handled the redirect from SSO provider and then set cookies for frontend and redirected back to frontend SPA. CEERIS is SPA, not SSR, but I think that current setup on CEERIS would work with SSR as well.

We could probably do the same with MSAL, but I am not 100% sure.

Note: Based on some examples, angular-auth-oidc-client also supports AD, at least to some extent.

@DarkoKukovec
Copy link
Member Author

angular-auth-oidc-client is another example of a lib using localStorage to store sensitive credentials.

The CEERIS approach is good, but it might not be possible or practical to do this in other cases (e.g. with microservices).

Basically, there is only one client side way to do this securely, and that is with service workers. I didn't find a good lib for this, but I'm working on something for that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants