ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
 

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 34 of file Twitter.php.

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

34  {
35  assert('is_array($info)');
36  assert('is_array($config)');
37 
38  // Call the parent constructor first, as required by the interface
39  parent::__construct($info, $config);
40 
41  $configObject = SimpleSAML_Configuration::loadFromArray($config, 'authsources[' . var_export($this->authId, TRUE) . ']');
42 
43  $this->key = $configObject->getString('key');
44  $this->secret = $configObject->getString('secret');
45  $this->force_login = $configObject->getBoolean('force_login', FALSE);
46  $this->include_email = $configObject->getBoolean('include_email', FALSE);
47  }
$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 55 of file Twitter.php.

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

55  {
56  assert('is_array($state)');
57 
58  // We are going to need the authId in order to retrieve this authentication source later
59  $state[self::AUTHID] = $this->authId;
60 
61  $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
62 
63  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
64  // Get the request token
65  $linkback = SimpleSAML\Module::getModuleURL('authtwitter/linkback.php', array('AuthState' => $stateID));
66  $requestToken = $consumer->getRequestToken('https://api.twitter.com/oauth/request_token', array('oauth_callback' => $linkback));
67  SimpleSAML\Logger::debug("Got a request token from the OAuth service provider [" .
68  $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
69 
70  $state['authtwitter:authdata:requestToken'] = $requestToken;
71  SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
72 
73  // Authorize the request token
74  $url = 'https://api.twitter.com/oauth/authenticate';
75  if ($this->force_login) {
76  $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, array('force_login' => 'true'));
77  }
78  $consumer->getAuthorizeRequest($url, $requestToken);
79  }
static debug($string)
Definition: Logger.php:213
$requestToken
Definition: demo.php:33
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
$consumer
Definition: demo.php:30
Create styles array
The data for the language used.
$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 82 of file Twitter.php.

References $accessToken, $attributes, $consumer, $key, $requestToken, $state, $userdata, array, SimpleSAML\Logger\debug(), and string.

82  {
83  $requestToken = $state['authtwitter:authdata:requestToken'];
84  $parameters = array();
85 
86  if (!isset($_REQUEST['oauth_token'])) {
87  throw new SimpleSAML_Error_BadRequest("Missing oauth_token parameter.");
88  }
89  if ($requestToken->key !== (string)$_REQUEST['oauth_token']) {
90  throw new SimpleSAML_Error_BadRequest("Invalid oauth_token parameter.");
91  }
92 
93  if (!isset($_REQUEST['oauth_verifier'])) {
94  throw new SimpleSAML_Error_BadRequest("Missing oauth_verifier parameter.");
95  }
96  $parameters['oauth_verifier'] = (string)$_REQUEST['oauth_verifier'];
97 
98  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
99 
100  SimpleSAML\Logger::debug("oauth: Using this request token [" .
101  $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
102 
103  // Replace the request token with an access token
104  $accessToken = $consumer->getAccessToken('https://api.twitter.com/oauth/access_token', $requestToken, $parameters);
105  SimpleSAML\Logger::debug("Got an access token from the OAuth service provider [" .
106  $accessToken->key . "] with the secret [" . $accessToken->secret . "]");
107 
108  $verify_credentials_url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
109  if ($this->include_email) {
110  $verify_credentials_url = $verify_credentials_url . '?include_email=true';
111  }
112  $userdata = $consumer->getUserInfo($verify_credentials_url, $accessToken);
113 
114  if (!isset($userdata['id_str']) || !isset($userdata['screen_name'])) {
115  throw new SimpleSAML_Error_AuthSource($this->authId, 'Authentication error: id_str and screen_name not set.');
116  }
117 
118  $attributes = array();
119  foreach($userdata AS $key => $value) {
120  if (is_string($value))
121  $attributes['twitter.' . $key] = array((string)$value);
122  }
123 
124  $attributes['twitter_at_screen_name'] = array('@' . $userdata['screen_name']);
125  $attributes['twitter_screen_n_realm'] = array($userdata['screen_name'] . '@twitter.com');
126  $attributes['twitter_targetedID'] = array('http://twitter.com!' . $userdata['id_str']);
127 
128  $state['Attributes'] = $attributes;
129  }
Add rich text string
static debug($string)
Definition: Logger.php:213
$userdata
Definition: demo.php:48
$attributes
$requestToken
Definition: demo.php:33
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
$consumer
Definition: demo.php:30
Create styles array
The data for the language used.
$accessToken
Definition: demo.php:45
+ Here is the call graph for this function:

Field Documentation

◆ $force_login

sspmod_authtwitter_Auth_Source_Twitter::$force_login
private

Definition at line 25 of file Twitter.php.

◆ $key

sspmod_authtwitter_Auth_Source_Twitter::$key
private

Definition at line 23 of file Twitter.php.

Referenced by finalStep().

◆ $secret

sspmod_authtwitter_Auth_Source_Twitter::$secret
private

Definition at line 24 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: