-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add SPA Form Based Authentication instructions #36818
Conversation
Mind squashing all commits before this is merged? |
Squashed! |
🙈 The PR is closed and the preview is expired. |
Great, the preview link is now broken, looks like it was caused by merging quarkusio/quarkusio.github.io#1826? |
const removeCookie = `quarkus-credential=; Max-Age=0;path=/`; | ||
document.cookie = removeCookie; | ||
// redirect to main page | ||
window.location.href = "/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are documenting logout for SPA with AJAX, I hope this won't confuse users. I think there is many occasions where you want to redirect and it depends on use case whether you want to loose state and use window.location.href
or keep state and use routing function provided by TypeScript-based SPA framework (for I think it would be challenging to write SPA with only JS + AJAX).
So in short: I think you intention is rather meta-code than something users will copy & paste and your examples are great in that way, but cookie is going to be removed whether you redirect or not. You could just execute some post-logout actions or whatever.
To logout of the SPA you must destroy the cookie and redirect back to your main page.
That said, I wrote app that did exactly this redirect in past, so I'm well aware this can be a case. I'll leave decision whether to keep it or not on you, personally I don't like to create an impressions that you need to redirect in SPA, there are other ways to reset state while keeping session data in SPA FWs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik I updated it to say // perform post logout actions here such as redirecting back to your login page
to leave it up to the user what to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
I wonder if this could close #27389 (as front-end based solution), because it doesn't make sense to me to add |
@michalvavrik i can change to what you want but all of this I had to figure out piecing together tickets and info just trying to get this working. Deleting the cookie seemed like the only way to logout of the SPA. Do you have an alternative? |
Maybe we don't understand each other, I agree with deleting cookie, I just tried to point out that cookie is deleted whether you redirect or not and in SPA (am I wrong? I didn't write FE for about a year), when you do |
No I am using Quarkus quinoa and if you delete the cookie and redirect it takes me back to my login screen. However I get your point I could do React Router navigate to / and it works also. Let me update that section to be more clear! |
---- | ||
const logout= () => { | ||
// delete the credential cookie essentially killing the session | ||
const removeCookie = `quarkus-credential=; Max-Age=0;path=/`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work out of the box, with the httpOnly flag set to true by default ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sberyozkin out of the box it looks like httpOnly is set to false
by default:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@melloware thanks, https://github.com/quarkusio/quarkus/blob/main/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/FormAuthConfig.java#L127 indeed have a default false value. It should be set to true by default, but it is another issue.
So IMHO it has to be noted that this solution only works with the HttpOnly
disabled, and I wonder if it is a good idea to recommend a logout solution which depends on the cookie being accessible to JavaScript.
Should a logout handler solution be recommended ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. I guess I should mention that it has to be httponly false and also provide an example server side controller logout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be set to true by default
+1
I wonder if it is a good idea to recommend a logout solution which depends on the cookie being accessible to JavaScript.
Here @melloware tries to document logout for SPA. SPA FWs actively prevents XSS (sanitize) unless you explicitly override it, in which is you are aware of what you are doing. All points you raised are absolutely true, but what is recommended here is not dangerous for typical SPA.
That is why I suggested this new code examples should be rather treated as meta code, because JS + AJAX doesn't provide OOTB protection nor the typical way you handle things (how you store state, route, ...) with SPA.
Good points. I guess I should mention that it has to be httponly false and also provide an example server side controller logout?
+1
I'd also mention why - XSS and make it clear when it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This thread is on logout
, same is true for login
documented here because you won't be able to use this cookie for BE requests if you can't access it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you
Added docs for HttpOnly setting for cookie mentioning Included Client, RestEasy Classic, and Reactive examples of logging out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To logout of the SPA from the server the cookie can be set to
quarkus.http.auth.form.http-only-cookie=true
but and use this example code to destroy the cookie.
I don't believe we agree on basic principle of SPA, if you can't access credentials cookie, then you can't make authenticated HTTP requests to back-end, which means you need to leave SPA (for example submit form, click on hyperlink, ...), which means that is not SPA by definition.
I'm sorry @melloware this PR takes too long, you are putting a good work in, thank you. I'd suggest to strongly highlight perils of HttpOnly
set to false and that is it.
Hmm, there is one else thing and I should probably try it before I write more - did anyone tried what is effect of |
@michalvavrik I am testing all of this with a React SPA app right now And what I have verified.
|
Can you share the app (unless it is too much of a problem)? If you create HTTP client on front end, it will only have headers and cookies you set it, therefore you are the owner of logic what to do with |
Let me see if I can put together a simple reproducer for you. |
|
||
@POST | ||
public Response logout() { | ||
if (identity.getIdentity().isAnonymous()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Authenticated
would do a same job if you insist on 401. Personally I don't know what is expected behavior.
Thanks! As long as it is not too much of a job. |
@melloware never mind I remembered how it works, the browser is in control. Okay, I am fine with changes. I'll let @sberyozkin to do rest, thanks again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, we can follow up with a dedicated issue to set http only to true by default
Based on Zulip conversation with @sberyozkin and @michalvavrik