I assume that you have an relaystate parameter that sends the user to
site2 after logging into site1, so that site2 also authenticates the
user.
> Now we want, while user logs from site1, he need to authenticate for
> site1 and when user hits site2, we need to check whether saml already
> exists for this sp/idp, if yes we need to authenticate the site2.
>
> The reason is as of now it is 2 sites and loading / authenticating 2
> sites every time is fine. But on going forward, we will be having 50
> sites to share SSO and when user logs in from one site, it will load
> all 50 sites url for authenticating.
I assume you want the user to automatically be logged into the site if
a session already exists on the IdP. In that case you can try to use
passive authentication requests to the IdP. This allows you to
authenticate the user if it wouldn't require any user interaction (i.e.
password entry).
--
Olav Morken
UNINETT / Feide
Issue a passive request to the IdP. If it fails, continue as an
unauthenticated user?
First of all, you should upgrade to a more recent version of
simpleSAMLphp. Then you can do something like this:
<?php
session_start();
require_once('....../lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple('default-sp');
if (!$as->isAuthenticated() && !isset($_SESSION['passiveAttempted'])) {
$as->login(array(
'isPassive' => TRUE,
'ErrorURL' => 'https://.../passive_failed.php?ReturnTo=' .
urlencode(/* The URL of the current page. */),
));
} elseif($as->isAuthenticated()) {
/* We have an authenticated user. */
} else {
/*
* We have an unauthenticated user, but passive authentication
* has failed.
*/
}
You must also create a page to handle the failed logins. It should
probably look something like this:
<?php
if (!isset($_REQUEST['ReturnTo'])) {
die('Missing ReturnTo URL.');
}
session_start();
$_SESSION['passiveAttempted'] = TRUE;
header('Location: ' . (string)$_REQUEST['ReturnTo']);