Created
December 21, 2015 11:18
-
-
Save markguinn/203557ab0e5895b0f098 to your computer and use it in GitHub Desktop.
How we're handling OAuth+REST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Mark Guinn <mark@adaircreative.com> | |
* @date 12.18.2015 | |
* @package simple-giving | |
* @subpackage auth | |
*/ | |
class FacebookApi extends Object implements ISocialApi | |
{ | |
/** @var string */ | |
private static $app_id = ''; | |
/** @var string */ | |
private static $app_secret = ''; | |
/** | |
* Checks with the site to confirm that the given token is indeed valid | |
* and corresponds with the userID we were given. It can do anything else | |
* it needs as well (e.g. facebook provides a debug_token endpoint) | |
* | |
* @param string $token | |
* @param string $userID | |
* @return boolean | |
*/ | |
public function validateToken($token, $userID) { | |
$fb = new Facebook\Facebook([ | |
'app_id' => self::config()->app_id, | |
'app_secret' => self::config()->app_secret, | |
'default_graph_version' => 'v2.2', | |
]); | |
try { | |
// Returns a `Facebook\FacebookResponse` object | |
$response = $fb->get('/me?fields=id,name', $token); | |
} catch(Facebook\Exceptions\FacebookResponseException $e) { | |
SS_Log::log("Graph returned an error: " . $e->getMessage(), SS_Log::ERR); | |
return false; | |
} catch(Facebook\Exceptions\FacebookSDKException $e) { | |
SS_Log::log('Facebook SDK returned an error: ' . $e->getMessage(), SS_Log::ERR); | |
return false; | |
} | |
$user = $response->getGraphUser(); | |
return $user->getId() == $userID; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* | |
* @author Mark Guinn <mark@adaircreative.com> | |
* @date 12.18.2015 | |
* @package simple-giving | |
* @subpackage | |
*/ | |
class GoogleApi implements ISocialApi | |
{ | |
/** | |
* Checks with the site to confirm that the given token is indeed valid | |
* and corresponds with the userID we were given. It can do anything else | |
* it needs as well (e.g. facebook provides a debug_token endpoint) | |
* | |
* @param string $token | |
* @param string $userID | |
* @return boolean | |
*/ | |
public function validateToken($token, $userID) { | |
throw new RestSystemException('Google authentication has not been implemented yet. Coming soon!', 500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment