Ok, this one's a tricky one so hopefully I can properly explain what I'm trying to do. We are in the process of upgrading our storefront site to version 10. Part of what I ended up inheriting was some custom code that created a single sign-on experience between the storefront and another website (SiteB) that belonged to the client. Basically, if you tried to login from storefront, you would be redirected to SiteB and login there first. From there, you would be redirected back to storefront where it would use the email you used to log you in to the storefront site. I'm not entirely sure how it worked, but I do know that the previous developer did copy some code from Storefront's core signin code into our custom code file.
Fast forward to now, I've done my best to bring this code along and after taking care of various errors with it, it seems to be pretty close. The redirect works perfectly (from storefront to the SiteB and then back to Storefront) but unfortunately I'm not getting logged into Storefront when I return. I tried to get away with basically using the same code, but I'm realizing now that probably wasn't the right way to go about it. The code that had been copied from's source probably needs to be updated with 10's source. But I'm not entirely sure how to go about that. Looking at the AccountController, I do see there is a SignIn method as well as a Login method in AccountControllerHelper, but I'm not sure what the best way to utilize either of those would be. Can I simply call one of those two from my custom code or would I need to copy the code from them? I can provide code snippets if it would help. Or if there's a better way that I'm not seeing to accomplish this, I'm open to those ideas as well. Thanks in advance for any help!
in MultiStore by (555 points)

1 Answer

+1 vote
Best answer

I  haved copyied/mirrored the Admin/App_coded/ImpersonationHandler.cs code for logins like this in the past. Since that is basicly what you are doing with aditonal logic. Which boils down to tree calls: 

1. loggin in with the GetOwinContext

2. calling ExecuteSigninLogic

3. calling UpdateCustomerSession calls.

Which code wise looks like :

Customer ThisCustomer2 = new Customer(CustomerID);
Func<IClaimsIdentityProvider> ClaimsIdentityProviderFactory = DependencyResolver.Current.GetService<Func<IClaimsIdentityProvider>>();
var claimsIdentityProvider = ClaimsIdentityProviderFactory();
var identity = claimsIdentityProvider.Create(ThisCustomer2);

properties: new Microsoft.Owin.Security.AuthenticationProperties
	IsPersistent = true
identities: identity);

AppLogic.ExecuteSigninLogic(null, ThisCustomer2);
ThisCustomer2.ThisCustomerSession.UpdateCustomerSession(null, null);

Hope that helps point you in the right direction.

by (5k points)
selected by
Awesome, looks like that was exactly what I needed! Really appreciate it, thank you!