-
Notifications
You must be signed in to change notification settings - Fork 2.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
Implement a default service to link local user accounts with external ones during the registration process #16110
Conversation
… data feat(Users): changed account controller code to use new services feat(Users): load all services in reversed enum to ret last registered services feat(Users): updated view code resolve OrchardCMS#16026
I have some issue to test this changes ... I have my orchardcore project that could be useful to test this but I have to use the orchardcore code from this PR inside my solution... or I link all the source code on my PC to the solution but I have a lot of modules and is a long work or I create a nuget package to load in my solution... there is some best practice about it? Thank You. |
fix: fixed LinkParameterValue name in ViewData fix: added to DI context DefaultExternalLoginUserToRelateFinder
ok I have tested the code changes and seems 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.
Please also add a new line at the end of each new file you introduced.
src/OrchardCore.Modules/OrchardCore.Users/Services/DefaultExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Services/DefaultExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Services/DefaultExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Services/DefaultExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml
Outdated
Show resolved
Hide resolved
style: formatting comment and code style: added last extra line style: change var name to usrLocator docs: reviewd comment
fixed in bd01473 |
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.
@PiemP I pushed a direct comment to your branch with some cleanup to your code. I did the change online so I hope I broke nothing.
Here are some suggestions for you to consider.
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IExternalLoginUserToRelateFinder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml
Outdated
Show resolved
Hide resolved
@PiemP I did break the build. Please also move the class |
Update src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml Co-authored-by: Mike Alhayek <mike@crestapps.com>
Update src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml Co-authored-by: Mike Alhayek <mike@crestapps.com>
Update src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml Co-authored-by: Mike Alhayek <mike@crestapps.com>
@PiemP please request my review once you fix the build error and address my other comments. |
fix: build by move service to OrchardCore.Users.Core style: rename interface to IUserToExternalLoginProvider style: rename method to GetIdentifierKey style: rename service class to DefaultUserToExternalLoginProvider style: rename ViewData object to ExternalUserIdentifier
src/OrchardCore.Modules/OrchardCore.Users/Views/Account/LinkExternalLogin.cshtml
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IUserToExternalLoginProvider.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IUserToExternalLoginProvider.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IUserToExternalLoginProvider.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IUserToExternalLoginProvider.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IUserToExternalLoginProvider.cs
Outdated
Show resolved
Hide resolved
…ternalLogin.cshtml
…oExternalLoginProvider.cs
…oExternalLoginProvider.cs
Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
feat(Users.Abstractions): remove GetIdentifierKey style(Users.Core): change name to default service style(Users): change name to mappers prop and local var
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
fix: removed DefaultExternalLoginMapper fix: restored UsersServiceCollectionExtensions fix: implemente check of RequireUniqueEmail in AccountController
{ | ||
iUser = await _userManager.FindByEmailAsync(email); | ||
} | ||
iUser = await _userManager.FindByEmailAsync(info.GetEmail()); |
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.
Only this should be in the if
. Otherwise, it would require a unique e-mail even for accounts found by FindByLoginAsync()
above.
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 no problem to make the change but if FindByLoginAsync()
find a User, this code can't be execute.
OrchardCore/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Lines 382 to 403 in 3853b97
var iUser = await _userManager.FindByLoginAsync(info.LoginProvider, info.ProviderKey); | |
CopyTempDataErrorsToModelState(); | |
if (iUser != null) | |
{ | |
if (!await AddConfirmEmailErrorAsync(iUser) && !AddUserEnabledError(iUser)) | |
{ | |
await _accountEvents.InvokeAsync((e, user, modelState) => e.LoggingInAsync(user.UserName, (key, message) => modelState.AddModelError(key, message)), iUser, ModelState, _logger); | |
var signInResult = await ExternalLoginSignInAsync(iUser, info); | |
if (signInResult.Succeeded) | |
{ | |
return await LoggedInActionResultAsync(iUser, returnUrl, info); | |
} | |
else | |
{ | |
ModelState.AddModelError(string.Empty, S["Invalid login attempt."]); | |
} | |
} | |
} | |
else |
fixed in f2faf17
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'm not sure I understand. If FindByLoginAsync()
finds a user, then the code block you show will execute, and rightfully so. In your case, that would mean that their PLUTO ID matched, what means that they're definitely the same user. In your use case, it won't find a user when you want the second account with the same e-mail to log in. And you'll need to configure RequireUniqueEmail
as false
too.
fix: restored check of the email value
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.
Anybody with any further remarks? Otherwise, I'll merge this on Tuesday.
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs
Show resolved
Hide resolved
_identityOptions = identityOptions.Value; | ||
|
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.
_identityOptions = identityOptions.Value; | |
_identityOptions = identityOptions.Value; |
src/OrchardCore/OrchardCore.Users.Core/Extensions/ExternalLoginInfoExtensions.cs
Show resolved
Hide resolved
Sorry guys, I have remember why I have set up the PR with the services EXAMPLE CASE 1 (unwanted link user-login data request): USER A (registered in orchard by provider PLUTO) USER B (not registered in orchard, authentication with provider PLUTO) EXAMPLE CASE 2 (registered in local, but not with PLUTO, no link operation fired): USER A (registered in orchard by local registration) USER A (authentication with provider PLUTO) ---> The "second check" ratio is to relate a the login data to a local user but if a login provider have a different identifier it can't happen in the right way. I have create Sorry. I have made you to lose a lot of your time. |
Example 1 is now covered. Example 2 then is the inverse: it's not that two different user accounts have the same email, but the same user account has two emails. This was covered previously too: you need to save a ProviderKey at one point for the user, so it'll be found by FindByLoginAsync during Pluto login. Or, you can override FindByLoginAsync as mentioned previously. |
…ontroller.cs Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
So, I don't think anything else is needed here and this can be merged. @hishamco you had the latest remarks, please merge when you're OK with it. |
In the EXAMPLE 2, USER A is created locally by an administrator and doesn't have the record that say that is authenticated with PLUTO. If I override
|
At the end of the day, OC needs to be able to tell if a local user related to the external one exists. In your Example 2 it can't do this, because this information doesn't exist. Adding an extension point doesn't help with this. However, you can solve this, as mentioned above, by saving a As far as I understand, after this PR, both of your use cases are covered. |
@PiemP I will merge this, please consider Zoltan's last comment |
feat(Users): changed account controller code to use new services
feat(Users): load all services in reversed enum to ret last registered services
feat(Users): updated view code
resolve #16026