Skip to content

Commit

Permalink
DWF : fb.class.php
Browse files Browse the repository at this point in the history
  • Loading branch information
legagneur-matthieu committed Nov 22, 2017
1 parent 3eaf7cc commit 193a410
Show file tree
Hide file tree
Showing 82 changed files with 11,533 additions and 2 deletions.
92 changes: 92 additions & 0 deletions dwf/class/fb.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/**
* Cette classe permet de gérer une autentification via FaceBook
*
* @author LEGAGNEUR Matthieu <[email protected]>
*/
class fb {

const FB_SESSION_KEY = "fb_token";

private $_fb;
private $_fb_helper;

/**
* Permet de vérifier que le SDK FB a bien été appelé qu'une fois.
* @var boolean Permet de vérifier que le SDK FB a bien été appelé qu'une fois.
*/
private static $_called = false;

/**
* Cette classe permet de gérer une autentification via FaceBook
*
* @param string $app_id app_id de votre application FaceBook
* @param string $app_secret secret de votre application FaceBook
* @param string $default_graph_version Version de Graph
*/
public function __construct($app_id, $app_secret, $default_graph_version = "v2.11") {
if (!self::$_called) {
include __DIR__ . '/php-graph-sdk-5.x/src/Facebook/autoload.php';
self::$_called = true;
}
$this->_fb = new Facebook\Facebook(
['app_id' => $app_id, 'app_secret' => $app_secret, 'default_graph_version' => $default_graph_version]
);
$this->_fb_helper = $this->_fb->getRedirectLoginHelper();
}

/**
* Retourne l'url pour le bouton de connexion
* @param string $redirect_url URL de redirection
* @param array $permissions Tableau des permitions demandées pour l'authentification ( le mail est demandé par defaut)
* @return string URL de connexion
*/
public function getLoginUrl($redirect_url, $permissions = ["email"]) {
return $this->_fb_helper->getLoginUrl($redirect_url, $permissions);
}

/**
* Retourne l'url pour le bouton de deconnexion
* @param string $redirect_url URL de redirection
* @return string URL de deconnexion
*/
public function getLogoutUrl($redirect_url) {
return $this->_fb_helper->getLogoutUrl(session::get_val(fb::FB_SESSION_KEY), $redirect_url);
}

/**
* Retourne le token d'accès ( stocké dans session::get_val(fb::FB_SESSION_KEY) ) ou false
* @return boolean|string token d'accès ou false
*/
public function getAccessToken_session() {
try {
if (!session::get_val(fb::FB_SESSION_KEY) and $token = $this->_fb_helper->getAccessToken()) {
session::set_val(fb::FB_SESSION_KEY, $token->getValue());
}
return session::get_val(fb::FB_SESSION_KEY);
} catch (Exception $e) {
dwf_exception::print_exception($e);
return false;
}
}

/**
* Permet de lancer une requete a l'API de FaceBook et retourne le resultat
* @param string $method methode a utiliser (get, post ou del)
* @param string $req requete à envoyer
* @return mixed reponse de l'API
*/
public function request($method = "get", $req = "/me") {
return (session::get_val(fb::FB_SESSION_KEY) ? $this->_fb->$method($req, session::get_val(fb::FB_SESSION_KEY)) : false);
}

/**
* Retourne les données de l'utilisateur connecté (GraphUser)
* @return \Facebook\GraphNodes\GraphUser Données de l'utilisateur
*/
public function getGraphUser() {
return $this->request()->getGraphUser();
}

}
4 changes: 2 additions & 2 deletions dwf/class/paypal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class paypal {
private $_payment_method;

/**
* Permet de vérifier que le SDK PayPaj a bien été appelé qu'une fois.
* @var boolean Permet de vérifier que le SDK PayPaj a bien été appelé qu'une fois.
* Permet de vérifier que le SDK PayPal a bien été appelé qu'une fois.
* @var boolean Permet de vérifier que le SDK PayPal a bien été appelé qu'une fois.
*/
private static $_called = false;

Expand Down
19 changes: 19 additions & 0 deletions dwf/class/php-graph-sdk-5.x/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2017 Facebook, Inc.

You are hereby granted a non-exclusive, worldwide, royalty-free license to
use, copy, modify, and distribute this software in source code or binary
form for use in connection with the web services and APIs provided by
Facebook.

As with any software that integrates with the Facebook platform, your use
of this software is subject to the Facebook Developer Principles and
Policies [http://developers.facebook.com/policy/]. This copyright notice
shall be included in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions dwf/class/php-graph-sdk-5.x/phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset>
<file>src/</file>
<file>tests/</file>
<arg value="spn" />
<rule ref="PSR2" />
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php
/**
* Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
* form for use in connection with the web services and APIs provided by
* Facebook.
*
* As with any software that integrates with the Facebook platform, your use
* of this software is subject to the Facebook Developer Principles and
* Policies [http://developers.facebook.com/policy/]. This copyright notice
* shall be included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace Facebook\Authentication;

/**
* Class AccessToken
*
* @package Facebook
*/
class AccessToken
{
/**
* The access token value.
*
* @var string
*/
protected $value = '';

/**
* Date when token expires.
*
* @var \DateTime|null
*/
protected $expiresAt;

/**
* Create a new access token entity.
*
* @param string $accessToken
* @param int $expiresAt
*/
public function __construct($accessToken, $expiresAt = 0)
{
$this->value = $accessToken;
if ($expiresAt) {
$this->setExpiresAtFromTimeStamp($expiresAt);
}
}

/**
* Generate an app secret proof to sign a request to Graph.
*
* @param string $appSecret The app secret.
*
* @return string
*/
public function getAppSecretProof($appSecret)
{
return hash_hmac('sha256', $this->value, $appSecret);
}

/**
* Getter for expiresAt.
*
* @return \DateTime|null
*/
public function getExpiresAt()
{
return $this->expiresAt;
}

/**
* Determines whether or not this is an app access token.
*
* @return bool
*/
public function isAppAccessToken()
{
return strpos($this->value, '|') !== false;
}

/**
* Determines whether or not this is a long-lived token.
*
* @return bool
*/
public function isLongLived()
{
if ($this->expiresAt) {
return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2);
}

if ($this->isAppAccessToken()) {
return true;
}

return false;
}

/**
* Checks the expiration of the access token.
*
* @return boolean|null
*/
public function isExpired()
{
if ($this->getExpiresAt() instanceof \DateTime) {
return $this->getExpiresAt()->getTimestamp() < time();
}

if ($this->isAppAccessToken()) {
return false;
}

return null;
}

/**
* Returns the access token as a string.
*
* @return string
*/
public function getValue()
{
return $this->value;
}

/**
* Returns the access token as a string.
*
* @return string
*/
public function __toString()
{
return $this->getValue();
}

/**
* Setter for expires_at.
*
* @param int $timeStamp
*/
protected function setExpiresAtFromTimeStamp($timeStamp)
{
$dt = new \DateTime();
$dt->setTimestamp($timeStamp);
$this->expiresAt = $dt;
}
}
Loading

0 comments on commit 193a410

Please sign in to comment.