From 852ee7e32a75aac93263e6b465567eedfd0f02d5 Mon Sep 17 00:00:00 2001
From: Thijs Kinkhorst <thijs@kinkhorst.com>
Date: Sun, 27 May 2018 13:43:32 +0000
Subject: [PATCH] Remove authmyspace module. The service is no longer offered.

---
 attributemap/myspace2name.php                 |  16 --
 config-templates/authsources.php              |  11 --
 docs/simplesamlphp-changelog.md               |   3 +
 modules/.gitignore                            |   1 -
 modules/authmyspace/default-disable           |   3 -
 modules/authmyspace/docs/oauthmyspace.md      |  25 ----
 .../authmyspace/lib/Auth/Source/MySpace.php   | 137 ------------------
 modules/authmyspace/www/linkback.php          |  42 ------
 .../smartattributes/docs/smartattributes.md   |   1 -
 .../lib/Auth/Process/SmartID.php              |   1 -
 10 files changed, 3 insertions(+), 237 deletions(-)
 delete mode 100644 attributemap/myspace2name.php
 delete mode 100644 modules/authmyspace/default-disable
 delete mode 100644 modules/authmyspace/docs/oauthmyspace.md
 delete mode 100644 modules/authmyspace/lib/Auth/Source/MySpace.php
 delete mode 100644 modules/authmyspace/www/linkback.php

diff --git a/attributemap/myspace2name.php b/attributemap/myspace2name.php
deleted file mode 100644
index 6111f61d0..000000000
--- a/attributemap/myspace2name.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-$attributemap = array(
-
-    // See http://developerwiki.myspace.com/index.php?title=People_API for attributes
-
-    // Generated MySpace Attributes
-    'myspace_user'            => 'eduPersonPrincipalName', // username OR uid @ myspace.com
-    'myspace_targetedID'      => 'eduPersonTargetedID', // http://myspace.com!uid
-    'myspace_username'        => 'uid', // myspace username (maybe numeric uid)
-
-    // Attributes Returned by MySpace
-    'myspace.name.givenName'  => 'givenName',
-    'myspace.name.familyName' => 'sn',
-    'myspace.displayName'     => 'displayName',
-    'myspace.profileUrl'      => 'labeledURI',
-);
diff --git a/config-templates/authsources.php b/config-templates/authsources.php
index bccb964fd..2588ed784 100644
--- a/config-templates/authsources.php
+++ b/config-templates/authsources.php
@@ -195,17 +195,6 @@ $config = array(
     ),
     */
 
-    /*
-    // MySpace OAuth Authentication API.
-    // Register your application to get an API key here:
-    //  http://developer.myspace.com/
-    'myspace' => array(
-        'authmyspace:MySpace',
-        'key' => 'xxxxxxxxxxxxxxxx',
-        'secret' => 'xxxxxxxxxxxxxxxx',
-    ),
-    */
-
     /*
     // Microsoft Account (Windows Live ID) Authentication API.
     // Register your application to get an API key here:
diff --git a/docs/simplesamlphp-changelog.md b/docs/simplesamlphp-changelog.md
index 85c85b6e8..a69623d88 100644
--- a/docs/simplesamlphp-changelog.md
+++ b/docs/simplesamlphp-changelog.md
@@ -41,6 +41,9 @@ Released TBD
   * Use configuration assertion lifetime when available.
   * Use `adfs:wreply` parameter when available.
 
+### authmyspace
+  * Module removed because service is no longer available.
+
 ### cas
   * Respect all LDAP options in LDAP call.
 
diff --git a/modules/.gitignore b/modules/.gitignore
index 14877bd3f..bcf421d67 100644
--- a/modules/.gitignore
+++ b/modules/.gitignore
@@ -7,7 +7,6 @@
 !/authcrypt/
 !/authfacebook/
 !/authlinkedin/
-!/authmyspace/
 !/authorize/
 !/authtwitter/
 !/authwindowslive/
diff --git a/modules/authmyspace/default-disable b/modules/authmyspace/default-disable
deleted file mode 100644
index fa0bd82e2..000000000
--- a/modules/authmyspace/default-disable
+++ /dev/null
@@ -1,3 +0,0 @@
-This file indicates that the default state of this module
-is disabled. To enable, create a file named enable in the
-same directory as this file.
diff --git a/modules/authmyspace/docs/oauthmyspace.md b/modules/authmyspace/docs/oauthmyspace.md
deleted file mode 100644
index 98b97b805..000000000
--- a/modules/authmyspace/docs/oauthmyspace.md
+++ /dev/null
@@ -1,25 +0,0 @@
-Using the MySpace authentication source with SimpleSAMLphp
-==========================================================
-
-Remember to configure `authsources.php`, with both your Client ID and Secret key.
-
-To get an API key and a secret, register the application at:
-
- * <http://developer.myspace.com/Modules/Apps/Pages/CreateAppAccount.aspx>
-
-Create a MySpace ID App and set the callback evaluation URL to be:
-
- * `http://sp.example.org/`
-
-Replace `sp.example.org` with your hostname.
-
-## Testing authentication
-
-On the SimpleSAMLphp frontpage, go to the *Authentication* tab, and use the link:
-
-  * *Test configured authentication sources*
-
-Then choose the *myspace* authentication source.
-
-Expected behaviour would then be that you are sent to MySpace, and asked to login.
-There is no consent screen for attribute release.
diff --git a/modules/authmyspace/lib/Auth/Source/MySpace.php b/modules/authmyspace/lib/Auth/Source/MySpace.php
deleted file mode 100644
index 26b8a1c57..000000000
--- a/modules/authmyspace/lib/Auth/Source/MySpace.php
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-
-require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/oauth/libextinc/OAuth.php');
-
-/**
- * Authenticate using MySpace.
- *
- * @author Brook Schofield, TERENA.
- * @package SimpleSAMLphp
- */
-class sspmod_authmyspace_Auth_Source_MySpace extends SimpleSAML_Auth_Source {
-
-	/**
-	 * The string used to identify our states.
-	 */
-	const STAGE_INIT = 'authmyspace:init';
-
-	/**
-	 * The key of the AuthId field in the state.
-	 */
-	const AUTHID = 'authmyspace:AuthId';
-
-	private $key;
-	private $secret;
-
-
-	/**
-	 * Constructor for this authentication source.
-	 *
-	 * @param array $info  Information about this authentication source.
-	 * @param array $config  Configuration.
-	 */
-	public function __construct($info, $config) {
-		assert(is_array($info));
-		assert(is_array($config));
-
-		// Call the parent constructor first, as required by the interface
-		parent::__construct($info, $config);
-
-		if (!array_key_exists('key', $config))
-			throw new Exception('MySpace authentication source is not properly configured: missing [key]');
-
-		$this->key = $config['key'];
-
-		if (!array_key_exists('secret', $config))
-			throw new Exception('MySpace authentication source is not properly configured: missing [secret]');
-
-		$this->secret = $config['secret'];
-	}
-
-
-	/**
-	 * 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);
-
-	}
-
-
-
-	public function finalStep(&$state) {
-
-		$requestToken = $state['authmyspace:requestToken'];
-
-		$consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
-
-		SimpleSAML\Logger::debug("oauth: Using this request token [" .
-			$requestToken->key . "] with the secret [" . $requestToken->secret . "]");
-
-		// Replace the request token with an access token
-		$accessToken = $consumer->getAccessToken('http://api.myspace.com/access_token', $requestToken);
-		SimpleSAML\Logger::debug("Got an access token from the OAuth service provider [" .
-			$accessToken->key . "] with the secret [" . $accessToken->secret . "]");
-
-		// People API -  http://developerwiki.myspace.com/index.php?title=People_API
-		$userdata = $consumer->getUserInfo('http://api.myspace.com/1.0/people/@me/@self?fields=@all', $accessToken);
-
-		$attributes = array();
-
-		if (is_array($userdata['person'])) {
-			foreach($userdata['person'] AS $key => $value) {
-				if (is_string($value) || is_int($value))
-					$attributes['myspace.' . $key] = array((string)$value);
-
-				if (is_array($value)) {
-					foreach($value AS $key2 => $value2) {
-						if (is_string($value2) || is_int($value2))
-							$attributes['myspace.' . $key . '.' . $key2] = array((string)$value2);
-					}
-				}
-			}
-
-			if (array_key_exists('id', $userdata['person']) ) {
-
-				// person-id in the format of myspace.com.person.1234567890
-				if (preg_match('/(\d+)$/',$userdata['person']['id'],$matches)) {
-					$attributes['myspace_targetedID'] = array('http://myspace.com!' . $matches[1]);
-					$attributes['myspace_uid'] = array($matches[1]);
-					$attributes['myspace_user'] = array($matches[1] . '@myspace.com');
-				}
-			}
-
-			// profileUrl in the format http://www.myspace.com/username
-			if (array_key_exists('profileUrl', $userdata['person']) ) {
-				if (preg_match('@/([^/]+)$@',$userdata['person']['profileUrl'],$matches)) {
-					$attributes['myspace_username'] = array($matches[1]);
-					$attributes['myspace_user'] = array($matches[1] . '@myspace.com');
-				}
-			}
-		}
-
-		SimpleSAML\Logger::debug('MySpace Returned Attributes: '. implode(", ",array_keys($attributes)));
-
-		$state['Attributes'] = $attributes;
-	}
-}
diff --git a/modules/authmyspace/www/linkback.php b/modules/authmyspace/www/linkback.php
deleted file mode 100644
index 296807844..000000000
--- a/modules/authmyspace/www/linkback.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-
-/**
- * Handle linkback() response from MySpace.
- */
-
-if (!array_key_exists('stateid', $_REQUEST)) {
-	throw new Exception('State Lost - not returned by MySpace Auth');
-}
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['stateid'], sspmod_authmyspace_Auth_Source_MySpace::STAGE_INIT);
-
-if (array_key_exists('oauth_problem', $_REQUEST)) {
-	// oauth_problem of 'user_refused' means user chose not to login with MySpace
-	if (strcmp($_REQUEST['oauth_problem'],'user_refused') == 0) {
-		$e = new SimpleSAML_Error_UserAborted();
-		SimpleSAML_Auth_State::throwException($state, $e);
-	}
-
-	// Error
-	$e = new SimpleSAML_Error_Error('Authentication failed: ' . $_REQUEST['oauth_problem']);
-	SimpleSAML_Auth_State::throwException($state, $e);
-}
-
-if (array_key_exists('oauth_verifier', $_REQUEST)) {
-	$state['authmyspace:oauth_verifier'] = $_REQUEST['oauth_verifier'];
-} else {
-	throw new Exception('OAuth verifier not returned.');;
-}
-
-// Find authentication source
-assert(array_key_exists(sspmod_authmyspace_Auth_Source_MySpace::AUTHID, $state));
-$sourceId = $state[sspmod_authmyspace_Auth_Source_MySpace::AUTHID];
-
-$source = SimpleSAML_Auth_Source::getById($sourceId);
-if ($source === NULL) {
-	throw new Exception('Could not find authentication source with id ' . $sourceId);
-}
-
-$source->finalStep($state);
-
-SimpleSAML_Auth_Source::completeAuth($state);
-
diff --git a/modules/smartattributes/docs/smartattributes.md b/modules/smartattributes/docs/smartattributes.md
index 0c2c8c136..f6015259a 100644
--- a/modules/smartattributes/docs/smartattributes.md
+++ b/modules/smartattributes/docs/smartattributes.md
@@ -21,7 +21,6 @@ The filter has the following configuration options:
 	* facebook_targetedID
 	* twitter_targetedID
 	* windowslive_targetedID
-	* myspace_targetedID
 	* linkedin_targetedID
 * `id_attribute`. A string to use as the name of the newly added attribute. Defaults to `smart_id`.
 * `add_authority`. A boolean to indicate whether or not to append the SAML AuthenticatingAuthority to the resulting identifier. This can be useful to indicate what SAML IdP was used, in case the original identifier is not scoped. Defaults to `TRUE`.
diff --git a/modules/smartattributes/lib/Auth/Process/SmartID.php b/modules/smartattributes/lib/Auth/Process/SmartID.php
index d9ae21230..278ea921d 100644
--- a/modules/smartattributes/lib/Auth/Process/SmartID.php
+++ b/modules/smartattributes/lib/Auth/Process/SmartID.php
@@ -16,7 +16,6 @@ class sspmod_smartattributes_Auth_Process_SmartID extends SimpleSAML_Auth_Proces
         'facebook_targetedID',
         'twitter_targetedID',
         'windowslive_targetedID',
-        'myspace_targetedID',
         'linkedin_targetedID',
     );
 
-- 
GitLab