Create oauth controller interface for oauth-specific actions; small refactoring on tabs.js

This commit is contained in:
Duncan Sommerville 2015-09-16 15:29:10 -04:00
parent 7006b55818
commit 9ed3145473
5 changed files with 80 additions and 50 deletions

View file

@ -3,7 +3,7 @@
require_once "ThirdPartyController.php";
require_once "ise/php-soundcloud/src/Soundcloud/Service.php";
class SoundcloudController extends ThirdPartyController {
class SoundcloudController extends ThirdPartyController implements OAuth2Controller {
/**
* @var SoundcloudService
@ -23,6 +23,39 @@ class SoundcloudController extends ThirdPartyController {
$this->_service = new SoundcloudService();
}
/**
* Send user to SoundCloud to authorize before being redirected
*
* @return void
*/
public function authorizeAction() {
$auth_url = $this->_service->getAuthorizeUrl();
header('Location: ' . $auth_url);
}
/**
* Clear the previously saved request token from preferences
*
* @return void
*/
public function deauthorizeAction() {
$function = $this->_SERVICE_TOKEN_ACCESSOR;
Application_Model_Preference::$function("");
header('Location: ' . $this->_baseUrl . 'preference'); // Redirect back to the preference page
}
/**
* Called when user successfully completes SoundCloud authorization
* Store the returned request token for future requests
*
* @return void
*/
public function redirectAction() {
$code = $_GET['code'];
$this->_service->requestNewAccessToken($code);
header('Location: ' . $this->_baseUrl . 'preference'); // Redirect back to the preference page
}
/**
* Fetch the permalink to a file on SoundCloud and redirect to it.
*/