ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
sspmod_authmyspace_Auth_Source_MySpace Class Reference
+ Inheritance diagram for sspmod_authmyspace_Auth_Source_MySpace:
+ Collaboration diagram for sspmod_authmyspace_Auth_Source_MySpace:

Public Member Functions

 __construct ($info, $config)
 Constructor for this authentication source. More...
 
 authenticate (&$state)
 Log-in using MySpace 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 = 'authmyspace:init'
 The string used to identify our states. More...
 
const AUTHID = 'authmyspace:AuthId'
 The key of the AuthId field in the state. More...
 

Private Attributes

 $key
 
 $secret
 

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 MySpace.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_authmyspace_Auth_Source_MySpace::__construct (   $info,
  $config 
)

Constructor for this authentication source.

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

Definition at line 33 of file MySpace.php.

References $config, and $info.

33  {
34  assert('is_array($info)');
35  assert('is_array($config)');
36 
37  // Call the parent constructor first, as required by the interface
38  parent::__construct($info, $config);
39 
40  if (!array_key_exists('key', $config))
41  throw new Exception('MySpace authentication source is not properly configured: missing [key]');
42 
43  $this->key = $config['key'];
44 
45  if (!array_key_exists('secret', $config))
46  throw new Exception('MySpace authentication source is not properly configured: missing [secret]');
47 
48  $this->secret = $config['secret'];
49  }
$info
Definition: index.php:5

Member Function Documentation

◆ authenticate()

sspmod_authmyspace_Auth_Source_MySpace::authenticate ( $state)

Log-in using MySpace platform.

Parameters
array&$stateInformation about the current authentication.

Definition at line 57 of file MySpace.php.

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

57  {
58  assert('is_array($state)');
59 
60  // We are going to need the authId in order to retrieve this authentication source later
61  $state[self::AUTHID] = $this->authId;
62 
63  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
64 
65  // Get the request token
66  $requestToken = $consumer->getRequestToken('http://api.myspace.com/request_token');
67  SimpleSAML\Logger::debug("Got a request token from the OAuth service provider [" .
68  $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
69 
70  $state['authmyspace:requestToken'] = $requestToken;
71 
72  $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
73  SimpleSAML\Logger::debug('authmyspace auth state id = ' . $stateID);
74 
75  // Authorize the request token
76  $consumer->getAuthorizeRequest('http://api.myspace.com/authorize', $requestToken, TRUE, SimpleSAML\Module::getModuleUrl('authmyspace') . '/linkback.php?stateid=' . $stateID);
77 
78  }
static debug($string)
Definition: Logger.php:213
$requestToken
Definition: demo.php:33
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Attribute-related utility methods.
$consumer
Definition: demo.php:30
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
+ Here is the call graph for this function:

◆ finalStep()

sspmod_authmyspace_Auth_Source_MySpace::finalStep ( $state)

Definition at line 82 of file MySpace.php.

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

82  {
83 
84  $requestToken = $state['authmyspace:requestToken'];
85 
86  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
87 
88  SimpleSAML\Logger::debug("oauth: Using this request token [" .
89  $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
90 
91  // Replace the request token with an access token
92  $accessToken = $consumer->getAccessToken('http://api.myspace.com/access_token', $requestToken);
93  SimpleSAML\Logger::debug("Got an access token from the OAuth service provider [" .
94  $accessToken->key . "] with the secret [" . $accessToken->secret . "]");
95 
96  // People API - http://developerwiki.myspace.com/index.php?title=People_API
97  $userdata = $consumer->getUserInfo('http://api.myspace.com/1.0/people/@me/@self?fields=@all', $accessToken);
98 
99  $attributes = array();
100 
101  if (is_array($userdata['person'])) {
102  foreach($userdata['person'] AS $key => $value) {
103  if (is_string($value) || is_int($value))
104  $attributes['myspace.' . $key] = array((string)$value);
105 
106  if (is_array($value)) {
107  foreach($value AS $key2 => $value2) {
108  if (is_string($value2) || is_int($value2))
109  $attributes['myspace.' . $key . '.' . $key2] = array((string)$value2);
110  }
111  }
112  }
113 
114  if (array_key_exists('id', $userdata['person']) ) {
115 
116  // person-id in the format of myspace.com.person.1234567890
117  if (preg_match('/(\d+)$/',$userdata['person']['id'],$matches)) {
118  $attributes['myspace_targetedID'] = array('http://myspace.com!' . $matches[1]);
119  $attributes['myspace_uid'] = array($matches[1]);
120  $attributes['myspace_user'] = array($matches[1] . '@myspace.com');
121  }
122  }
123 
124  // profileUrl in the format http://www.myspace.com/username
125  if (array_key_exists('profileUrl', $userdata['person']) ) {
126  if (preg_match('@/([^/]+)$@',$userdata['person']['profileUrl'],$matches)) {
127  $attributes['myspace_username'] = array($matches[1]);
128  $attributes['myspace_user'] = array($matches[1] . '@myspace.com');
129  }
130  }
131  }
132 
133  SimpleSAML\Logger::debug('MySpace Returned Attributes: '. implode(", ",array_keys($attributes)));
134 
135  $state['Attributes'] = $attributes;
136  }
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

◆ $key

sspmod_authmyspace_Auth_Source_MySpace::$key
private

Definition at line 23 of file MySpace.php.

Referenced by finalStep().

◆ $secret

sspmod_authmyspace_Auth_Source_MySpace::$secret
private

Definition at line 24 of file MySpace.php.

◆ AUTHID

const sspmod_authmyspace_Auth_Source_MySpace::AUTHID = 'authmyspace:AuthId'

The key of the AuthId field in the state.

Definition at line 21 of file MySpace.php.

◆ STAGE_INIT

const sspmod_authmyspace_Auth_Source_MySpace::STAGE_INIT = 'authmyspace:init'

The string used to identify our states.

Definition at line 16 of file MySpace.php.


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