Cross Site Authentication

David Wilkinson asked on June 22, 2016 15:05

Hi, I have 2 sites within 1 Kentico shared installation.

I have 1 user that needs access to both sites and can log into each site separately but always need to enter their username and password to each site.

Q. - How can I get user_x to navigate from 1 kentico site (via a asp:button) to the other without entering the username and password ?

protected void btn_othersite_click(object sender, EventArgs e) { Response.Redirect(RS_URL); }

RS_URL = secure home page of site2

It should be possible as global administrator accounts can bounce between both sites without typing username & password to access the site.

Thanks for any direction you can give. Dave

Correct Answer

Trevor Fayas answered on June 22, 2016 16:44

Sadly the client did not give an okay to share the code that we developed for their site.

The best i can do at this point is just give the general overview of what it does so you can try to code it yourself : /

  1. Create either a Select box, or bullet list of post-back links of the sites
  2. On select/click, get the site they selected
  3. If the user is logged in, generate a random GUID, and add to a key to the Application (it's like a Session but shared across the application), that contains that user's GUID
  4. Clear the page response and write a form (with document onload form submit) that posts the GUID to your receiving page on the other site
  5. On the receiving page, have a control that takes the posted value, looks in the Application for a matching GUID, if it finds one grab the user's GUID value and log them in using Kentico's API, and then delete the application key.

I added some extra logic myself to handle aliases and auto-redirect to similar pages, but that this should hopefully help. Sorry about that :(

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on June 22, 2016 15:14

Hi,

Can you have a look at the following default setting: Automatically sign-in user when site changes

Image Text

0 votesVote for this answer Mark as a Correct answer

David Wilkinson answered on June 22, 2016 15:19

Yeah... doesn't work with site users, just administrators. :(

0 votesVote for this answer Mark as a Correct answer

Dawid Jachnik answered on June 22, 2016 15:20

Hello,

Changing the sites in the administration without authentication is by default. So check the Settings > Global > Security & Membership > Administration group > Automatically sign-in user when site changes this setting should be enabled.

In the live site I think you need to make your custom one.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 22, 2016 15:20

I think the auto sign in is only when using the Admin's site swapping.

To do what you want to do, it does require a little code. What i did is create a post-back button that when they click it, it adds a random GUID to the application settings with their login info, and post that to a receiving page that takes the GUID, looks up the user, logs them in then deletes the random GUID info. So it's pretty much impossible to exploit.

I'll try to export them for ya, give me a bit!

0 votesVote for this answer Mark as a Correct answer

David Wilkinson answered on June 22, 2016 15:25 (last edited on June 22, 2016 16:15)

Sounds like Trevor you will be my savour.

Its my first cross site setup (every site I have done since 3.1a) I have never tried 2 sites in one kentico instance. Would have thought it would have worked out of the "box"

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 22, 2016 16:02

Positive, is this a v9 site? i can export the items in Version 9, it's what i have them in. The code will work in V8.0, 8.1, and 8.2 most likely with no problem, but i can't export the webpart settings in anything but what it was created in without recreating it.

0 votesVote for this answer Mark as a Correct answer

David Wilkinson answered on June 22, 2016 16:10

Its a v9 site. - i skipped v8

I really appreciate you helping me.

Dave

0 votesVote for this answer Mark as a Correct answer

David Wilkinson answered on June 23, 2016 11:54

Thanks Trevor.

Great guidance there, i will write it like that and post the results to share (if I get it working lol)

Dave

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.