Commit c7ae7d5c authored by Sonia Zorba's avatar Sonia Zorba
Browse files

sso 2019 changes

parent b0d644d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@ $url = "https://www.linkedin.com/oauth/v2/authorization?response_type=code";
$url .= "&client_id=" . $LinkedIn['id'];
$url .= "&client_id=" . $LinkedIn['id'];
$url .= "&redirect_uri=" . $LinkedIn['callback'];
$url .= "&redirect_uri=" . $LinkedIn['callback'];
$url .= "&state=789654123";
$url .= "&state=789654123";
$url .= "&scope=r_basicprofile r_emailaddress";
$url .= "&scope=r_liteprofile%20r_emailaddress%20w_member_social";


header("Location: $url");
header("Location: $url");
?>
?>
+32 −4
Original line number Original line Diff line number Diff line
@@ -82,7 +82,7 @@ if ($info1['http_code'] === 200) {


// Call to API
// Call to API
$conn2 = curl_init();
$conn2 = curl_init();
curl_setopt($conn2, CURLOPT_URL, "https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address,id)?format=json");
curl_setopt($conn2, CURLOPT_URL, "https://api.linkedin.com/v2/me");
curl_setopt($conn2, CURLOPT_HTTPHEADER, array(
curl_setopt($conn2, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $access_token
    'Authorization: Bearer ' . $access_token
));
));
@@ -107,13 +107,41 @@ if ($info2['http_code'] === 200) {
    $user = $userHandler->findUserByIdentity(RAP\Identity::LINKEDIN, $typedId);
    $user = $userHandler->findUserByIdentity(RAP\Identity::LINKEDIN, $typedId);


    if ($user === null) {
    if ($user === null) {

      // Recall to API for email
      $conn2 = curl_init();
      curl_setopt($conn2, CURLOPT_URL, "https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))");
      curl_setopt($conn2, CURLOPT_HTTPHEADER, array(
           'Authorization: Bearer ' . $access_token
      ));

      curl_setopt($conn2, CURLOPT_RETURNTRANSFER, true);
      $result = curl_exec($conn2);
      $info2 = curl_getinfo($conn2);

      if ($info2['http_code'] === 200) {
        $data2 = json_decode($result, TRUE);

        curl_close($conn2);

        if (isset($data['errorCode'])) {
          $errorMessage = $data['message'];
          die($errorMessage);
        }
      } else {
           //show information regarding the error
           $errorMessage = "Error: LinkedIn server response code: " . $info2['http_code'] . " - ";
           $errorMessage = $errorMessage . curl_error($conn2);
           curl_close($conn2);
           die($errorMessage);
      }
        // Create new user
        // Create new user
        $user = new RAP\User();
        $user = new RAP\User();


        $identity = new RAP\Identity(RAP\Identity::LINKEDIN);
        $identity = new RAP\Identity(RAP\Identity::LINKEDIN);
        $identity->email = $data['emailAddress'];
        $identity->email = $data2['elements'][0]['handle~']['emailAddress'];
        $identity->name = $data['firstName'];
        $identity->name = $data['localizedFirstName'];
        $identity->surname = $data['lastName'];
        $identity->surname = $data['localizedLastName'];
        $identity->typedId = $typedId;
        $identity->typedId = $typedId;


        $user->addIdentity($identity);
        $user->addIdentity($identity);
+21 −0
Original line number Original line Diff line number Diff line
@@ -91,6 +91,27 @@ class CallbackHandler {
        return null;
        return null;
    }
    }


    /**
     * Each callback has a title,a logo and auth in order to avoid confusion in
     * user and show in which application they are logging in using RAP.
     * @param type $callbackURL
     * @return type the callback auth or null if the callback URL is not listed
     * in configuration file or it doesn't have a auth.
     */
    public function getCallbackAuth($callbackURL) {

        foreach ($this->callbacks as $callback) {
            if ($callback['url'] === $callbackURL) {
                if (array_key_exists('auth', $callback)) {
                    return $callback['auth'];
                } else {
                    return null;
                }
            }
        }

        return null;
    }
    public function manageLoginRedirect($user, SessionData $session) {
    public function manageLoginRedirect($user, SessionData $session) {


        if ($session->getCallbackURL() === null) {
        if ($session->getCallbackURL() === null) {
+6 −0
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ class SessionData {
    private $callbackURL;
    private $callbackURL;
    private $callbackTitle;
    private $callbackTitle;
    private $callbackLogo;
    private $callbackLogo;
    private $callbackAuth;
    public $user;
    public $user;
    public $userSearchResults;
    public $userSearchResults;
    public $x509DataToRegister;
    public $x509DataToRegister;
@@ -75,6 +76,7 @@ class SessionData {
        $this->callbackURL = $callbackHandler->filterCallbackURL($callbackURL);
        $this->callbackURL = $callbackHandler->filterCallbackURL($callbackURL);
        $this->callbackTitle = $callbackHandler->getCallbackTitle($callbackURL);
        $this->callbackTitle = $callbackHandler->getCallbackTitle($callbackURL);
        $this->callbackLogo = $callbackHandler->getCallbackLogo($callbackURL);
        $this->callbackLogo = $callbackHandler->getCallbackLogo($callbackURL);
        $this->callbackAuth = $callbackHandler->getCallbackAuth($callbackURL);
        $this->save();
        $this->save();
    }
    }


@@ -90,6 +92,10 @@ class SessionData {
        return $this->callbackLogo;
        return $this->callbackLogo;
    }
    }


    public function getCallbackAuth() {
        return $this->callbackAuth;
    }

    /**
    /**
     * Perform a user search and store the results inside the session. This is
     * Perform a user search and store the results inside the session. This is
     * used for achieving the user selection using the dropdown menu in the join
     * used for achieving the user selection using the dropdown menu in the join
+51 −9
Original line number Original line Diff line number Diff line
@@ -18,9 +18,16 @@ include 'include/header.php';
            </h1>
            </h1>
        </div>
        </div>
    </div>
    </div>

    <?php
        if ($session->getCallbackAuth() != null) {
            $authType = $session->getCallbackAuth();
        }
    ?>
    <div class="row" id="auth-panel">
    <div class="row" id="auth-panel">
        <div class="col-xs-12 text-center">
        <div class="col-xs-12 text-center">
            <?php if (isset($auth['eduGAIN'])) { ?>
            <?php if (isset($auth['eduGAIN']) and 
                    ( !isset($authType) or in_array('eduGAIN', $authType))) { ?>
                <div class="home-box">
                <div class="home-box">
                    <div class="img-wrapper">
                    <div class="img-wrapper">
                        <a href="edugain?callback=<?php echo $session->getCallbackURL(); ?>">
                        <a href="edugain?callback=<?php echo $session->getCallbackURL(); ?>">
@@ -33,26 +40,60 @@ include 'include/header.php';
            <?php if (isset($auth['Google']) || isset($auth['Facebook']) || isset($auth['LinkedIn'])) { ?>
            <?php if (isset($auth['Google']) || isset($auth['Facebook']) || isset($auth['LinkedIn'])) { ?>
                <div class="home-box">
                <div class="home-box">
                    <div class="img-wrapper">
                    <div class="img-wrapper">
                        <?php if (isset($auth['Google'])) { ?>
                        <?php if (isset($auth['Google']) and 
                                 ( !isset($authType) or 
                                   in_array('Google', $authType))) { ?>
                            <a href="google?callback=<?php echo $session->getCallbackURL(); ?>" class="animated pulse">
                            <a href="google?callback=<?php echo $session->getCallbackURL(); ?>" class="animated pulse">
                        <?php if ((isset($auth['Facebook']) and
                                  ( !isset($authType) or 
                                    in_array('Facebook', $authType))) or
                                  (isset($auth['LinkedIn']) and
                                  ( !isset($authType) or 
                                    in_array('LinkedIn', $authType))))  { ?>
                                <img src="img/google-60.png" alt="Google Logo" />
                                <img src="img/google-60.png" alt="Google Logo" />
                            </a>
                            </a>
                        <?php } ?>
                        <?php } else {?>
                        <?php if (isset($auth['Facebook'])) { ?>
                                <img src="img/google-200.png" alt="Google Logo" />
                            </a>
                        <?php } } ?>
                        <?php if (isset($auth['Facebook']) and
                                 ( !isset($authType) or 
                                   in_array('Facebook', $authType))) { ?>
                            <a href="facebook?callback=<?php echo $session->getCallbackURL(); ?>">
                            <a href="facebook?callback=<?php echo $session->getCallbackURL(); ?>">
                        <?php if ((isset($auth['Google']) and
                                  ( !isset($authType) or 
                                    in_array('Google', $authType))) or
                                  (isset($auth['LinkedIn']) and
                                  ( !isset($authType) or 
                                    in_array('LinkedIn', $authType))))  { ?>
                                <img src="img/facebook-60.png" alt="Facebook Logo" />
                                <img src="img/facebook-60.png" alt="Facebook Logo" />
                            </a>
                            </a>
                        <?php } ?>
                        <?php } else {?>
                        <?php if (isset($auth['LinkedIn'])) { ?>
                                <img src="img/facebook-200.png" alt="Facebook Logo" />
                            </a>
                        <?php } } ?>
                        <?php if (isset($auth['LinkedIn']) and
                                 ( !isset($authType) or 
                                   in_array('LinkedIn', $authType))) { ?>
                            <a href="linkedin?callback=<?php echo $session->getCallbackURL(); ?>">
                            <a href="linkedin?callback=<?php echo $session->getCallbackURL(); ?>">
                        <?php if ((isset($auth['Facebook']) and
                                  ( !isset($authType) or 
                                    in_array('Facebook', $authType))) or
                                  (isset($auth['Google']) and
                                  ( !isset($authType) or 
                                    in_array('Google', $authType))))  { ?>
                                <img src="img/linkedin-60.png" alt="LinkedIn Logo" />
                                <img src="img/linkedin-60.png" alt="LinkedIn Logo" />
                            </a>
                            </a>
                        <?php } ?>
                        <?php } else {?>
                                <img src="img/linkedin-200.png" alt="LinkedIn Logo" />
                            </a>
                        <?php } } ?>
                    </div>
                    </div>
                    Use these Logos to Login or Register to the RAP facility with your social identity
                    Use these Logos to Login or Register to the RAP facility with your social identity
                </div>
                </div>
            <?php } ?>
            <?php } ?>
            <?php if (isset($auth['X.509'])) { ?>
            <?php if (isset($auth['X.509']) and
                    ( !isset($authType) or in_array('X.509', $authType))) { ?>
                <div class="home-box">
                <div class="home-box">
                    <div class="img-wrapper">
                    <div class="img-wrapper">
                        <a href="x509?callback=<?php echo $session->getCallbackURL(); ?>">
                        <a href="x509?callback=<?php echo $session->getCallbackURL(); ?>">
@@ -62,7 +103,8 @@ include 'include/header.php';
                    Use the X.509 Logo to Login with your personal certificate (IGTF and TERENA-TACAR, are allowed).
                    Use the X.509 Logo to Login with your personal certificate (IGTF and TERENA-TACAR, are allowed).
                </div>
                </div>
            <?php } ?>
            <?php } ?>
            <?php if (isset($auth['DirectIdP'])) { ?>
            <?php if (isset($auth['DirectIdP']) and (!isset($authType) or 
                                      in_array('DirectIdP', $authType))) { ?>
                <div class="home-box">
                <div class="home-box">
                    <div class="img-wrapper">
                    <div class="img-wrapper">
                        <a href="direct?callback=<?php echo $session->getCallbackURL(); ?>">
                        <a href="direct?callback=<?php echo $session->getCallbackURL(); ?>">