-
Notifications
You must be signed in to change notification settings - Fork 977
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
feat: improved oidc flow on duplicate account registration #3151
Conversation
d040a53
to
b4b9bb4
Compare
route: registration, | ||
}) | ||
|
||
cy.get('[data-testid="ui/message/4000007"]').should("be.visible") |
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.
checks if the duplicate error message is present on the form
cy.get("[name='provider'][value='hydra']").should("be.visible") | ||
cy.get("[name='provider'][value='google']").should("be.visible") | ||
cy.get("[name='provider'][value='github']").should("be.visible") |
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.
ensure we have form values for logging in
|
||
cy.get("input[name='identifier']").type(email) | ||
cy.get("input[name='password']").type(password) | ||
cy.submitPasswordForm() |
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.
ensure we can actually log in after getting such an error.
password: | ||
hooks: | ||
- hook: session |
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.
In the spa
profile we always have a session after registration. Just added it here to the oidc
profile used by the express app.
272b57e
to
ee59362
Compare
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.
Looking good already. Just a few nits.
Codecov Report
@@ Coverage Diff @@
## master #3151 +/- ##
==========================================
+ Coverage 77.61% 77.69% +0.08%
==========================================
Files 317 317
Lines 20009 20036 +27
==========================================
+ Hits 15530 15567 +37
+ Misses 3289 3279 -10
Partials 1190 1190
... and 2 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
9d19fa6
to
9b1b977
Compare
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 for fixing the issues :)
LGTM, apart from the nil return in handleError
.
return err | ||
} | ||
x.AcceptToRedirectOrJSON(w, r, s.d.Writer(), lf, lf.AppendTo(s.d.Config().SelfServiceFlowLoginUI(r.Context())).String()) | ||
return nil |
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 seems wrong, right? This should either return the error, or not return at all, IIUC. If we return nil
other callers "up" the line might end up with a situation, where err == nil
, while there was an error.
Do we have a test covering this code 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.
The x.AcceptToRedirectJSON
doesn't return anything.
It redirects or writes json back to the browser.
the return nil just prevents the rest of the function from executing. In this case we don't want to propagate the error further since we want to return a login flow with the error message attached to the login flow.
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.
We are always calling this function as part of the return part of functions, which return someValue, error
. For example here https://github.com/ory/kratos/pull/3151/files/9b1b977a8bbc43e86687bb631fc46ac4f3d08241.
In that example, if you now return nil
from handleError
, the returned values of processRegistration
will be nil, nil
. And that is an issue, because the caller of processRegistration
(here for example) will check whether err != nil
, which is false
(because you returned nil
here) and then assume that the *login.Flow
is a valid object and processRegistration
completed successfully. It will then go on and reference the nil
pointer (*login.Flow
), which will panic.
I would really like to see a test that executes this code path. Did you already write one?
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.
I have a test for this though.
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.
and an e2e test https://github.com/ory/kratos/pull/3151/files#diff-2695d9d779ed70b5b6a2d9cc5111dcac495b41bfc8353c0e0a50154ff787f7a6
Remember this PR changes the behaviour of the registration flow with oidc
when the account already exists.
Instead of just giving back an error code and message, it responds with a new Login flow and the error message inside the login
flow.
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.
I think you should return ErrAbortFlow
here. This prevents further calls in case something changes at some point.
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.
LGTM
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.
Nicely done
return err | ||
} | ||
x.AcceptToRedirectOrJSON(w, r, s.d.Writer(), lf, lf.AppendTo(s.d.Config().SelfServiceFlowLoginUI(r.Context())).String()) | ||
return nil |
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.
I think you should return ErrAbortFlow
here. This prevents further calls in case something changes at some point.
Ups, please address the one comment with abort flow |
This PR improves the OIDC registration flow when a duplicate account error happens.
Currently the flow looks as follows:
Instead of causing a confusing redirect loop we should show the user the error with a fresh login flow (since the account exists). This also gives the user the option to do a recovery flow.
Related issue(s)
Checklist
introduces a new feature.
contributing code guidelines.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got the approval (please contact
[email protected]) from the maintainers to push
the changes.
works.
Further Comments