Esempio n. 1
0
 /**
  * Log-in using Facebook cronus
  *
  * @param array &$state  Information about the current authentication.
  */
 public function authenticate(&$state)
 {
     assert('is_array($state)');
     /* We are going to need the authId in order to retrieve this authentication source later. */
     $state[self::AUTHID] = $this->authId;
     $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
     SimpleSAML_Logger::debug('facebook auth state id = ' . $stateID);
     $facebook = new Facebook($this->api_key, $this->secret);
     $u = $facebook->require_login(SimpleSAML_Module::getModuleUrl('authfacebook') . '/linkback.php?next=' . $stateID);
     # http://developers.facebook.com/documentation.php?v=1.0&method=users.getInfo
     /* Causes an notice / warning...
     		if ($facebook->api_client->error_code) {
     			throw new Exception('Unable to load profile from facebook');
     		}
     		*/
     // http://developers.facebook.com/docs/reference/rest/users.getInfo
     $info = $facebook->api_client->users_getInfo($u, array('uid', 'first_name', 'middle_name', 'last_name', 'name', 'locale', 'current_location', 'affiliations', 'pic_square', 'profile_url', 'sex', 'email', 'pic', 'username', 'about_me', 'status', 'profile_blurb'));
     $attributes = array();
     foreach ($info[0] as $key => $value) {
         if (is_string($value) && !empty($value)) {
             $attributes['facebook.' . $key] = array((string) $value);
         }
     }
     if (array_key_exists('username', $info[0])) {
         $attributes['facebook_user'] = array($info[0]['username'] . '@facebook.com');
     } else {
         $attributes['facebook_user'] = array($u . '@facebook.com');
     }
     $attributes['facebook_targetedID'] = array('http://facebook.com!' . $u);
     $attributes['facebook_cn'] = array($info[0]['name']);
     SimpleSAML_Logger::debug('Facebook Returned Attributes: ' . implode(", ", array_keys($attributes)));
     $state['Attributes'] = $attributes;
 }
Esempio n. 2
0
 public function finalStep(&$state)
 {
     SimpleSAML_Logger::debug("oauth wrap:  Using this verification code [" . $state['authwindowslive:wrap_verification_code'] . "]");
     // Retrieve Access Token
     // Documentation at: http://msdn.microsoft.com/en-us/library/ff749686.aspx
     $postData = 'wrap_client_id=' . urlencode($this->key) . '&wrap_client_secret=' . urlencode($this->secret) . '&wrap_callback=' . urlencode(SimpleSAML_Module::getModuleUrl('authwindowslive') . '/linkback.php') . '&wrap_verification_code=' . urlencode($state['authwindowslive:wrap_verification_code']);
     $context = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postData));
     $result = \SimpleSAML\Utils\HTTP::fetch('https://consent.live.com/AccessToken.aspx', $context);
     parse_str($result, $response);
     // error checking of $response to make sure we can proceed
     if (!array_key_exists('wrap_access_token', $response)) {
         throw new Exception('[' . $response['error_code'] . '] ' . $response['wrap_error_reason'] . "\r\nNo wrap_access_token returned - cannot proceed\r\n" . $response['internal_info']);
     }
     SimpleSAML_Logger::debug("Got an access token from the OAuth WRAP service provider [" . $response['wrap_access_token'] . "] for user [" . $response['uid'] . "]");
     // Documentation at: http://msdn.microsoft.com/en-us/library/ff751708.aspx
     $opts = array('http' => array('header' => "Accept: application/json\r\nAuthorization: WRAP access_token=" . $response['wrap_access_token'] . "\r\n"));
     $data = \SimpleSAML\Utils\HTTP::fetch('https://apis.live.net/V4.1/cid-' . $response['uid'] . '/Profiles', $opts);
     $userdata = json_decode($data, TRUE);
     $attributes = array();
     $attributes['windowslive_uid'] = array($response['uid']);
     $attributes['windowslive_targetedID'] = array('http://windowslive.com!' . $response['uid']);
     $attributes['windowslive_user'] = array($response['uid'] . '@windowslive.com');
     if (array_key_exists('Entries', $userdata)) {
         foreach ($userdata['Entries'][0] as $key => $value) {
             if (is_string($value)) {
                 $attributes['windowslive.' . $key] = array((string) $value);
             }
         }
         if (array_key_exists('Emails', $userdata['Entries'][0])) {
             $attributes['windowslive_mail'] = array($userdata['Entries'][0]['Emails'][0]['Address']);
         }
     }
     SimpleSAML_Logger::debug('LiveID Returned Attributes: ' . implode(", ", array_keys($attributes)));
     $state['Attributes'] = $attributes;
 }
Esempio n. 3
0
 /**
  * Log-in using MySpace platform
  *
  * @param array &$state  Information about the current authentication.
  */
 public function authenticate(&$state)
 {
     assert('is_array($state)');
     /* We are going to need the authId in order to retrieve this authentication source later. */
     $state[self::AUTHID] = $this->authId;
     $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
     // Get the request token
     $requestToken = $consumer->getRequestToken('http://api.myspace.com/request_token');
     SimpleSAML_Logger::debug("Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
     $state['authmyspace:requestToken'] = $requestToken;
     $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
     SimpleSAML_Logger::debug('authmyspace auth state id = ' . $stateID);
     // Authorize the request token
     $consumer->getAuthorizeRequest('http://api.myspace.com/authorize', $requestToken, TRUE, SimpleSAML_Module::getModuleUrl('authmyspace') . '/linkback.php?stateid=' . $stateID);
 }
Esempio n. 4
0
 /**
  * Log-in using LinkedIn platform
  * Documentation at: http://developer.linkedin.com/docs/DOC-1008
  *
  * @param array &$state  Information about the current authentication.
  */
 public function authenticate(&$state)
 {
     assert('is_array($state)');
     // We are going to need the authId in order to retrieve this authentication source later
     $state[self::AUTHID] = $this->authId;
     $stateID = SimpleSAML_Auth_State::getStateId($state);
     SimpleSAML_Logger::debug('authlinkedin auth state id = ' . $stateID);
     $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
     // Get the request token
     $requestToken = $consumer->getRequestToken('https://api.linkedin.com/uas/oauth/requestToken', array('oauth_callback' => SimpleSAML_Module::getModuleUrl('authlinkedin') . '/linkback.php?stateid=' . $stateID));
     SimpleSAML_Logger::debug("Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
     $state['authlinkedin:requestToken'] = $requestToken;
     // Update the state
     SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
     // Authorize the request token
     $consumer->getAuthorizeRequest('https://www.linkedin.com/uas/oauth/authenticate', $requestToken);
 }
    $password_text = $this->t('{privacyidea:privacyidea:password_otp}');
}
if ($this->data['errorcode'] === "CHALLENGERESPONSE") {
    $password_text = $this->t('{privacyidea:privacyidea:otp}');
    SimpleSAML_Logger::debug("Attributes: " . print_r($this->data["chal_resp_attributes"], TRUE));
    $chal_resp_attributes = $this->data['chal_resp_attributes'];
    $hideResponseInput = $chal_resp_attributes->hideResponseInput;
    $chal_resp_message = $this->data['chal_resp_message'];
    // check if this is U2F
    $u2fSignRequest = $chal_resp_attributes->u2fSignRequest;
    SimpleSAML_Logger::debug("u2fSignRequest: " . print_r($u2fSignRequest, TRUE));
}
if ($u2fSignRequest) {
    // Add javascript for U2F support before including the header.
    $this->data['head'] = '<script type="text/javascript" src="' . SimpleSAML_Module::getModuleUrl('privacyidea/js/u2f-api.js') . '"></script>\\n';
    $this->data['head'] .= '<script type="text/javascript" src="' . SimpleSAML_Module::getModuleUrl('privacyidea/js/u2f.js') . '"></script>';
}
$this->data['header'] = $this->t('{privacyidea:privacyidea:header}');
if (strlen($this->data['username']) > 0) {
    $this->data['autofocus'] = 'password';
} else {
    $this->data['autofocus'] = 'username';
}
$this->includeAtTemplateBase('includes/header.php');
?>

<?php 
// If there is an error, which is NOT the challenge response
if ($this->data['errorcode'] !== NULL && $this->data['errorcode'] !== "CHALLENGERESPONSE") {
    ?>
<?php

$faventry = NULL;
foreach ($this->data['idplist'] as $tab => $slist) {
    if (!empty($this->data['preferredidp']) && array_key_exists($this->data['preferredidp'], $slist)) {
        $faventry = $slist[$this->data['preferredidp']];
    }
}
if (!array_key_exists('header', $this->data)) {
    $this->data['header'] = 'selectidp';
}
$this->data['header'] = $this->t($this->data['header']);
$this->data['jquery'] = array('version' => '1.6', 'core' => TRUE, 'ui' => TRUE, 'css' => TRUE);
$this->data['head'] = '<link rel="stylesheet" media="screen" type="text/css" href="' . SimpleSAML_Module::getModuleUrl('discopower/style.css') . '" />';
$this->data['head'] .= '<script type="text/javascript" src="' . SimpleSAML_Module::getModuleUrl('discopower/js/jquery.livesearch.js') . '"></script>';
$this->data['head'] .= '<script type="text/javascript" src="' . SimpleSAML_Module::getModuleUrl('discopower/js/' . $this->data['score'] . '.js') . '"></script>';
$this->data['head'] .= '<script type="text/javascript">

$(document).ready(function() {
	$("#discotabs").tabs({ selected: ' . $this->data['defaulttab'] . ' }); ';
$i = 0;
foreach ($this->data['idplist'] as $tab => $slist) {
    $this->data['head'] .= "\n" . '$("#query_' . $tab . '").liveUpdate("#list_' . $tab . '")' . ($i++ == 0 && empty($faventry) ? '.focus()' : '') . ';';
}
$this->data['head'] .= '
});

</script>';
if (!empty($faventry)) {
    $this->data['autofocus'] = 'favouritesubmit';
}
Esempio n. 7
0
 public function finalStep(&$state)
 {
     assert('is_array($state)');
     $stateID = SimpleSAML_Auth_State::getStateId($state);
     SimpleSAML_Logger::debug("oauth wrap:  Using this verification code [" . $state['authwindowslive:wrap_verification_code'] . "]");
     // Retrieve Access Token
     // Documentation at:  http://msdn.microsoft.com/en-us/library/live/hh243641
     // http://msdn.microsoft.com/en-us/library/live/hh243647.aspx
     $auth_code = $state['authwindowslive:wrap_verification_code'];
     $redirect_uri = SimpleSAML_Module::getModuleUrl('authwindowslive') . '/linkback.php?wrap_client_state=' . urlencode($stateID);
     $fields = array('code' => urlencode($auth_code), 'client_id' => urlencode($this->key), 'client_secret' => urlencode($this->secret), 'redirect_uri' => urlencode($redirect_uri), 'grant_type' => urlencode('authorization_code'));
     $post = '';
     foreach ($fields as $key => $value) {
         $post .= $key . '=' . $value . '&';
     }
     $post = rtrim($post, '&');
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://login.live.com/oauth20_token.srf');
     curl_setopt($curl, CURLOPT_POST, 5);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     $result = curl_exec($curl);
     curl_close($curl);
     $response = json_decode($result);
     $accesstoken = $response->access_token;
     SimpleSAML_Logger::debug('LIVE AccessToken: ' . $accesstoken);
     // $url = 'https://apis.live.net/v5.0/me/contacts?access_token='.$accesstoken.'';
     $url = 'https://apis.live.net/v5.0/me?access_token=' . $accesstoken . '';
     $xmlresponse = $this->curl_file_get_contents($url);
     SimpleSAML_Logger::debug('LIVE Response: ' . $xmlresponse);
     $xml = json_decode($xmlresponse, true);
     foreach ($xml as $key => $value) {
         SimpleSAML_Logger::debug('LIVE ' . $key . ':' . $value);
     }
     $attributes = array();
     $attributes['windowslive_uid'] = array($xml['id']);
     //$attributes['uid']=$attributes['windowslive_uid'];
     $attributes['windowslive_name'] = array($xml['name']);
     //$attributes['cn']=$attributes['windowslive_name'];
     $attributes['windowslive_first_name'] = array($xml['first_name']);
     //$attributes['givenName']=$attributes['windowslive_first_name'];
     $attributes['windowslive_last_name'] = array($xml['last_name']);
     //$attributes['sn']=$attributes['windowslive_last_name'];
     //$attributes['windowslive_link'] = array($xml['link']);
     $attributes['windowslive_email'] = array($xml['emails']['account']);
     //$attributes['mail']=$attributes['windowslive_email'];
     /*$attributes['windowslive_birth_month'] = array($xml['birth_month']);
     		$attributes['windowslive_gender'] = array($xml['gender']);
     		$attributes['windowslive_city'] = array($xml['addresses']['personal']['city']);
     		$attributes['windowslive_state'] = array($xml['addresses']['personal']['state']);
     		$attributes['windowslive_region'] = array($xml['addresses']['personal']['region']);
     		$attributes['windowslive_locale'] = array($xml['locale']);*/
     //$attributes['language']=$attributes['windowslive_locale'];
     //$attributes['windowslive_updated_time'] = array($xml['updated_time']);
     $attributes['windowslive_user'] = array($xml['id'] . '@live.com');
     $state['Attributes'] = $attributes;
 }