Formatting FKOauthDataStore

This commit is contained in:
Hypolite Petovan 2017-12-17 15:34:29 -05:00
parent 2978b1eef0
commit 910d3f7b5f

View file

@ -1,10 +1,12 @@
<?php <?php
/** /**
* @file src/Protocol/FKOAuthDataStore.php * @file src/Protocol/FKOAuthDataStore.php
* OAuth server * OAuth server
* Based on oauth2-php <http://code.google.com/p/oauth2-php/> * Based on oauth2-php <http://code.google.com/p/oauth2-php/>
* *
*/ */
namespace Friendica\Network; namespace Friendica\Network;
use Friendica\App; use Friendica\App;
@ -41,8 +43,8 @@ class FKOAuthDataStore extends OAuthDataStore
*/ */
public function lookup_consumer($consumer_key) public function lookup_consumer($consumer_key)
{ {
logger(__function__.":".$consumer_key); logger(__function__ . ":" . $consumer_key);
$s = dba::select('clients', array('client_id', 'pw', 'redirect_uri'), array('client_id' => $consumer_key)); $s = dba::select('clients', array('client_id', 'pw', 'redirect_uri'), array('client_id' => $consumer_key));
$r = dba::inArray($s); $r = dba::inArray($s);
@ -61,8 +63,8 @@ class FKOAuthDataStore extends OAuthDataStore
*/ */
public function lookup_token($consumer, $token_type, $token) public function lookup_token($consumer, $token_type, $token)
{ {
logger(__function__.":".$consumer.", ". $token_type.", ".$token); logger(__function__ . ":" . $consumer . ", " . $token_type . ", " . $token);
$s = dba::select('tokens', array('id', 'secret', 'scope', 'expires', 'uid'), array('client_id' => $consumer->key, 'scope' => $token_type, 'id' => $token)); $s = dba::select('tokens', array('id', 'secret', 'scope', 'expires', 'uid'), array('client_id' => $consumer->key, 'scope' => $token_type, 'id' => $token));
$r = dba::inArray($s); $r = dba::inArray($s);
@ -87,7 +89,7 @@ class FKOAuthDataStore extends OAuthDataStore
public function lookup_nonce($consumer, $token, $nonce, $timestamp) public function lookup_nonce($consumer, $token, $nonce, $timestamp)
{ {
$r = dba::select('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp], ['limit' => 1]); $r = dba::select('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp], ['limit' => 1]);
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
return new \OAuthToken($r['id'], $r['secret']); return new \OAuthToken($r['id'], $r['secret']);
} }
@ -102,7 +104,7 @@ class FKOAuthDataStore extends OAuthDataStore
*/ */
public function new_request_token($consumer, $callback = null) public function new_request_token($consumer, $callback = null)
{ {
logger(__function__.":".$consumer.", ". $callback); logger(__function__ . ":" . $consumer . ", " . $callback);
$key = self::genToken(); $key = self::genToken();
$sec = self::genToken(); $sec = self::genToken();
@ -137,7 +139,7 @@ class FKOAuthDataStore extends OAuthDataStore
*/ */
public function new_access_token($token, $consumer, $verifier = null) public function new_access_token($token, $consumer, $verifier = null)
{ {
logger(__function__.":".$token.", ". $consumer.", ". $verifier); logger(__function__ . ":" . $token . ", " . $consumer . ", " . $verifier);
// return a new access token attached to this consumer // return a new access token attached to this consumer
// for the user associated with this token if the request token // for the user associated with this token if the request token
@ -148,9 +150,9 @@ class FKOAuthDataStore extends OAuthDataStore
// get user for this verifier // get user for this verifier
$uverifier = Config::get("oauth", $verifier); $uverifier = Config::get("oauth", $verifier);
logger(__function__.":".$verifier.",".$uverifier); logger(__function__ . ":" . $verifier . "," . $uverifier);
if (is_null($verifier) || ($uverifier!==false)) { if (is_null($verifier) || ($uverifier !== false)) {
$key = self::genToken(); $key = self::genToken();
$sec = self::genToken(); $sec = self::genToken();
$r = dba::insert( $r = dba::insert(
@ -169,10 +171,8 @@ class FKOAuthDataStore extends OAuthDataStore
} }
} }
dba::delete('tokens', array('id' => $token->key)); dba::delete('tokens', array('id' => $token->key));
if (!is_null($ret) && !is_null($uverifier)) { if (!is_null($ret) && !is_null($uverifier)) {
Config::delete("oauth", $verifier); Config::delete("oauth", $verifier);
} }