Skip to content

Commit

Permalink
Using duellsy package and authentication complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Gleek committed May 29, 2014
1 parent ba6f5e8 commit 31ba2fd
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 380 deletions.
20 changes: 8 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
"homepage": "http://github.com/gleek/fluxpocket",
"license": "GPL-2.0",
"authors": [
{
"name": "Umar Ahmad",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "M",
"email": "m",
"role": "Developer"
}
],
{
"name": "Umar Ahmad",
"email": "[email protected]",
"role": "Developer"
}
],
"support": {
"issues": "http://github.com/gleek/fluxpocket/issues"
},
"require": {
"php": ">=5.3.2"
"php": ">=5.3.2",
"duellsy/pockpack": "2.*"
}
}
93 changes: 87 additions & 6 deletions lib/Drupal/fluxpocket/Plugin/Service/PocketAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

use Drupal\fluxpocket\Tasks\Exception;
use Drupal\fluxpocket\PocketClient;
use Drupal\fluxdropbox\DropboxAccountStorage;
use Drupal\fluxservice\Plugin\Entity\Account;
use Drupal\fluxpocket\Tasks\Pocket;
use Drupal\fluxpocket\Tasks\PocketAuth;
use Drupal\fluxpocket\Tasks\PocketQueue;
use Duellsy\Pockpack\Pockpack;
use Duellsy\Pockpack\PockpackAuth;
use Duellsy\Pockpack\PockpackQueue;
/**
* Account plugin implementation for Dropbox.
* Account plugin implementation for Pocket.
*/
class PocketAccount extends Account implements PocketAccountInterface {

Expand All @@ -39,4 +38,86 @@ public function prepareAccount() {
parent::prepareAccount();
$key = $this->getService()->getConsumerKey();
$redirect = $this->getRedirectUrl();
new Curl($key, $secret, $storage, $redirect);
$store = fluxservice_tempstore("fluxservice.account.{$this->bundle()}");
$store->setIfNotExists($this->identifier(), $this);
$plugin = $this->identifier();
//Using API to request token
$pock_auth = new PockpackAuth();
$request_token = $pock_auth->connect($key);
$_SESSION[$plugin] = $request_token;
unset($_GET['destination']);
drupal_goto($path = "https://getpocket.com/auth/authorize?request_token={$request_token}&redirect_uri={$redirect}");
}


public static function getAccountForOAuthCallback($key, $plugin) {
$store = fluxservice_tempstore("fluxservice.account.{$plugin}");
return $store->getIfOwner($key);
}

/**
* Builds the URL to redirect to after visiting dropbox for authentication.
*
*
* @return string
* The URL to redirect to after visiting the Dropbox OAauth endpoint for
* requesting access privileges from a user.
*/
protected function getRedirectUrl() {
return url("fluxservice/oauth/{$this->bundle()}/{$this->identifier()}", array('absolute' => TRUE));
}

/**
* {@inheritdoc}
*/
public function client() {
$service = $this->getService();
return PocketClient::factory(array(
'client_id' => $service->getConsumerKey()
));
}

/**
* {@inheritdoc}
*/
public function getDefaultSettings() {
return array(
'access_token' => '',
);
}

/**
* {@inheritdoc}
*/
public function accessOAuthCallback() {
// Ensure that all required request and account values are set.
$plugin = $this->identifier();
if (!isset($_SESSION[$plugin])) {
return FALSE;
}
return TRUE;
}

/**
* {@inheritdoc}
*/
public function processOAuthCallback() {
$key = $this->getService()->getConsumerKey();
$request_token = $_SESSION[$this->identifier()];
$client = new PockPackAuth();
$data = $client->receiveTokenAndUsername($key, $request_token);
$this->processAuthorizedAccount($data);

// Remove the temporarily stored account entity from the tempstore.
$store = fluxservice_tempstore("fluxservice.account.{$this->bundle()}");
$store->delete($this->identifier());
}
/**
* {@inheritdoc}
*/
protected function processAuthorizedAccount(array $response) {
// Build the label and remote id from the response data.
$this->setRemoteIdentifier($response['access_token'])->setLabel($response['username']);
}

}
5 changes: 2 additions & 3 deletions lib/Drupal/fluxpocket/PocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use Guzzle\Common\Collection;
use Guzzle\Plugin\Oauth\OauthPlugin;
use Guzzle\Service\Client;
use Drupal\fluxpocket\Tasks\Pocket;
use Drupal\fluxpocket\Tasks\PocketAuth;
use Duellsy\Pockpack\PockpackAuth;

/**
* Service client for the Pocket API.
Expand All @@ -20,7 +19,7 @@ class PocketClient extends Client {
* {@inheritdoc}
*/
public static function factory($config = array()) {
$client = new PocketAuth();
$client = new PockpackAuth();
$client->connect($config['client_id']);
return $client;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/Drupal/fluxpocket/Tasks/Exceptions.php

This file was deleted.

72 changes: 0 additions & 72 deletions lib/Drupal/fluxpocket/Tasks/Pocket.php

This file was deleted.

91 changes: 0 additions & 91 deletions lib/Drupal/fluxpocket/Tasks/PocketAuth.php

This file was deleted.

35 changes: 0 additions & 35 deletions lib/Drupal/fluxpocket/Tasks/PocketBase.php

This file was deleted.

Loading

0 comments on commit 31ba2fd

Please sign in to comment.