ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_authtwitter_Auth_Source_Twitter Class Reference
+ Inheritance diagram for sspmod_authtwitter_Auth_Source_Twitter:
+ Collaboration diagram for sspmod_authtwitter_Auth_Source_Twitter:

Public Member Functions

 __construct ($info, $config)
 Constructor for this authentication source. More...
 
 authenticate (&$state)
 Log-in using Twitter platform. More...
 
 finalStep (&$state)
 
- Public Member Functions inherited from SimpleSAML_Auth_Source
 __construct ($info, &$config)
 Constructor for an authentication source. More...
 
 getAuthId ()
 Retrieve the ID of this authentication source. More...
 
 authenticate (&$state)
 Process a request. More...
 
 reauthenticate (array &$state)
 Reauthenticate an user. More...
 
 initLogin ($return, $errorURL=null, array $params=array())
 Start authentication. More...
 
 logout (&$state)
 Log out from this authentication source. More...
 

Data Fields

const STAGE_INIT = 'twitter:init'
 The string used to identify our states. More...
 
const AUTHID = 'twitter:AuthId'
 The key of the AuthId field in the state. More...
 

Private Attributes

 $key
 
 $secret
 
 $force_login
 
 $include_email
 

Additional Inherited Members

- Static Public Member Functions inherited from SimpleSAML_Auth_Source
static getSourcesOfType ($type)
 Get sources of a specific type. More...
 
static completeAuth (&$state)
 Complete authentication. More...
 
static loginCompleted ($state)
 Called when a login operation has finished. More...
 
static completeLogout (&$state)
 Complete logout. More...
 
static getById ($authId, $type=null)
 Retrieve authentication source. More...
 
static logoutCallback ($state)
 Called when the authentication source receives an external logout request. More...
 
static getSources ()
 Retrieve list of authentication sources. More...
 
- Protected Member Functions inherited from SimpleSAML_Auth_Source
 addLogoutCallback ($assoc, $state)
 Add a logout callback association. More...
 
 callLogoutCallback ($assoc)
 Call a logout callback based on association. More...
 
- Static Protected Member Functions inherited from SimpleSAML_Auth_Source
static validateSource ($source, $id)
 Make sure that the first element of an auth source is its identifier. More...
 
- Protected Attributes inherited from SimpleSAML_Auth_Source
 $authId
 

Detailed Description

Definition at line 11 of file Twitter.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_authtwitter_Auth_Source_Twitter::__construct (   $info,
  $config 
)

Constructor for this authentication source.

Parameters
array$infoInformation about this authentication source.
array$configConfiguration.

Definition at line 49 of file Twitter.php.

References $config, $info, and SimpleSAML_Configuration\loadFromArray().

50  {
51  assert(is_array($info));
52  assert(is_array($config));
53 
54  // Call the parent constructor first, as required by the interface
55  parent::__construct($info, $config);
56 
57  $configObject = SimpleSAML_Configuration::loadFromArray($config, 'authsources[' . var_export($this->authId, true) . ']');
58 
59  $this->key = $configObject->getString('key');
60  $this->secret = $configObject->getString('secret');
61  $this->force_login = $configObject->getBoolean('force_login', false);
62  $this->include_email = $configObject->getBoolean('include_email', false);
63  }
$config
Definition: bootstrap.php:15
$info
Definition: index.php:5
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
+ Here is the call graph for this function:

Member Function Documentation

◆ authenticate()

sspmod_authtwitter_Auth_Source_Twitter::authenticate ( $state)

Log-in using Twitter platform.

Parameters
array&$stateInformation about the current authentication.

Definition at line 71 of file Twitter.php.

References SimpleSAML_Auth_Source\$authId, $state, $url, SimpleSAML\Logger\debug(), SimpleSAML\Module\getModuleURL(), and SimpleSAML_Auth_State\saveState().

72  {
73  assert(is_array($state));
74 
75  // We are going to need the authId in order to retrieve this authentication source later
76  $state[self::AUTHID] = $this->authId;
77 
78  $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
79 
80  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
81  // Get the request token
82  $linkback = SimpleSAML\Module::getModuleURL('authtwitter/linkback.php', array('AuthState' => $stateID));
83  $requestToken = $consumer->getRequestToken('https://api.twitter.com/oauth/request_token', array('oauth_callback' => $linkback));
84  SimpleSAML\Logger::debug("Got a request token from the OAuth service provider [" .
85  $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
86 
87  $state['authtwitter:authdata:requestToken'] = $requestToken;
88  SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
89 
90  // Authorize the request token
91  $url = 'https://api.twitter.com/oauth/authenticate';
92  if ($this->force_login) {
93  $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, array('force_login' => 'true'));
94  }
95  $consumer->getAuthorizeRequest($url, $requestToken);
96  }
static debug($string)
Definition: Logger.php:211
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:220
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
$url
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
+ Here is the call graph for this function:

◆ finalStep()

sspmod_authtwitter_Auth_Source_Twitter::finalStep ( $state)

Definition at line 99 of file Twitter.php.

References $attributes, $key, $state, and SimpleSAML\Logger\debug().

100  {
101  $requestToken = $state['authtwitter:authdata:requestToken'];
102  $parameters = array();
103 
104  if (!isset($_REQUEST['oauth_token'])) {
105  throw new SimpleSAML_Error_BadRequest("Missing oauth_token parameter.");
106  }
107  if ($requestToken->key !== (string)$_REQUEST['oauth_token']) {
108  throw new SimpleSAML_Error_BadRequest("Invalid oauth_token parameter.");
109  }
110 
111  if (!isset($_REQUEST['oauth_verifier'])) {
112  throw new SimpleSAML_Error_BadRequest("Missing oauth_verifier parameter.");
113  }
114  $parameters['oauth_verifier'] = (string)$_REQUEST['oauth_verifier'];
115 
116  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
117 
118  SimpleSAML\Logger::debug("oauth: Using this request token [" .
119  $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
120 
121  // Replace the request token with an access token
122  $accessToken = $consumer->getAccessToken('https://api.twitter.com/oauth/access_token', $requestToken, $parameters);
123  SimpleSAML\Logger::debug("Got an access token from the OAuth service provider [" .
124  $accessToken->key . "] with the secret [" . $accessToken->secret . "]");
125 
126  $verify_credentials_url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
127  if ($this->include_email) {
128  $verify_credentials_url = $verify_credentials_url . '?include_email=true';
129  }
130  $userdata = $consumer->getUserInfo($verify_credentials_url, $accessToken);
131 
132  if (!isset($userdata['id_str']) || !isset($userdata['screen_name'])) {
133  throw new SimpleSAML_Error_AuthSource($this->authId, 'Authentication error: id_str and screen_name not set.');
134  }
135 
136  $attributes = array();
137  foreach ($userdata as $key => $value) {
138  if (is_string($value)) {
139  $attributes['twitter.' . $key] = array((string)$value);
140  }
141  }
142 
143  $attributes['twitter_at_screen_name'] = array('@' . $userdata['screen_name']);
144  $attributes['twitter_screen_n_realm'] = array($userdata['screen_name'] . '@twitter.com');
145  $attributes['twitter_targetedID'] = array('http://twitter.com!' . $userdata['id_str']);
146 
147  $state['Attributes'] = $attributes;
148  }
static debug($string)
Definition: Logger.php:211
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
+ Here is the call graph for this function:

Field Documentation

◆ $force_login

sspmod_authtwitter_Auth_Source_Twitter::$force_login
private

Definition at line 36 of file Twitter.php.

◆ $include_email

sspmod_authtwitter_Auth_Source_Twitter::$include_email
private

Definition at line 41 of file Twitter.php.

◆ $key

sspmod_authtwitter_Auth_Source_Twitter::$key
private

Definition at line 26 of file Twitter.php.

Referenced by finalStep().

◆ $secret

sspmod_authtwitter_Auth_Source_Twitter::$secret
private

Definition at line 31 of file Twitter.php.

◆ AUTHID

const sspmod_authtwitter_Auth_Source_Twitter::AUTHID = 'twitter:AuthId'

The key of the AuthId field in the state.

Definition at line 21 of file Twitter.php.

◆ STAGE_INIT

const sspmod_authtwitter_Auth_Source_Twitter::STAGE_INIT = 'twitter:init'

The string used to identify our states.

Definition at line 16 of file Twitter.php.


The documentation for this class was generated from the following file: