-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Generic OAuth: Prevent adding duplicated users #32286
Conversation
pkg/services/sqlstore/user_auth.go
Outdated
} | ||
} | ||
// create authInfo record to link accounts | ||
} else if authQuery.Result == nil && query.AuthModule != "" { |
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.
Trying to make this less ugly.
764faa6
to
18fce06
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.
Great work with the conversion of tests 🎉
I added some additional comments. Let me know if you don't understand and we can discuss 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.
See comment and let me know if I misunderstood
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.
Great. Now I think it should work according to my idea. Not sure I'm correct though and that it works :) I will test it manually as well. Added a comment regarding a missing error check.
Would be great to add a test for generic_oauth in sqlstore/user_auth_test.go as well to validate the changes works as expected.
a38c2ad
to
7cdfd72
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.
Works as expected 👍
Verified no new rows in user_auth is created when signing in with existing generic_oauth user that exists in user_auth and that a new row is created for generic_oauth user when there are no rows in the user_auth table.
One thing left, I added a comment. Otherwise this should be good to merge I think since it prevents adding duplicate rows in the user_auth table. Great work
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 left a couple comments/suggestions.
After this been merged need to think about what's left in regard to duplicate rows
|
||
// Expect to pass since there's a matching login user | ||
getTime = func() time.Time { return time.Now().AddDate(0, 0, -2) } | ||
query := &models.GetUserByAuthInfoQuery{Login: login, AuthModule: "oauth_generic_oauth", AuthId: ""} |
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.
Can you put this in a const variable since used in 3 different places now?
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's used with different Login
field so we shall create a method / func for that - think it's not necessary?
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.
Was referring to the magic string oauth_generic_oauth
. Sorry for being unclear
Co-authored-by: Marcus Efraimsson <[email protected]>
What this PR does / why we need it:
The purpose of this PR is to prevent adding duplicated users in
user_auth
column, when logging in.Essentially, since we'll have to deal with many duplicated entries already, we add a check where:
Notes:
auth_id
is now removed, since no auth_id exists when using Generic OAuth. This was the main cause of the problem, since every time a new user with Generic OAuth login existed was re-added on the database.Which issue(s) this PR fixes:
Fixes #23077
Special notes for your reviewer:
Steps to reproduce:
[auth.generic_oauth]
config in yourcustom.ini
file inside grafana repo.grafana.db
, browseuser_auth
table, and you'll see something like: