contributte / facebook
Easy-to-use Facebook login wrapper for [`Nette Framework`](https://github.com/nette/).
Fund package maintenance!
f3l1x
contributte.org/partners.html
Installs: 637 475
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 4
Forks: 10
Open Issues: 1
pkg:composer/contributte/facebook
Requires
- php: >=7.2
- facebook/graph-sdk: dev-next
- nette/di: ^3.0.0
- nette/http: ^3.0.1
Requires (Dev)
- ninjify/nunjuck: ^0.4
- ninjify/qa: ^0.13
- phpstan/phpstan: ^1.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-nette: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
This package is auto-updated.
Last update: 2025-12-09 12:23:44 UTC
README
Website 🚀 contributte.org | Contact 👨🏻💻 f3l1x.io | Twitter 🐦 @contributte
Disclaimer
| ⚠️ | This project is no longer being maintained. |
|---|
| Composer | contributte/facebook |
|---|---|
| Version | |
| PHP | |
| License |
About
Easy-to-use Facebook login wrapper for Nette Framework.
Installation
composer require contributte/facebook
Setup
extensions: facebook: Contributte\Facebook\DI\Nette\FacebookExtension
If you are using PHP 8.0+, you need to use forked version of facebook/graph-sdk. You can rely on our fork holyfork/facebook-graph-sdk, it's tested and working.
{
"repositories": [
{ "type": "git", "url": "https://github.com/holyfork/facebook-graph-sdk" }
]
}
Configuration
You need to create a FacebookApp and supply these parameters:
- appId
- appSecret
- defaultGraphVersion (optional)
- persistentDataHandler (optional) default value: session
- httpClientHandler (optional)
facebook: appId: %yourAppId% appSecret: %yourAppSecret%
Usage
Simple example how to use Facebook Login in Presenter
namespace App\Presenters; use Contributte\Facebook\Exceptions\FacebookLoginException; use Contributte\Facebook\FacebookLogin; use Nette\Application\Responses\RedirectResponse; use Nette\Application\UI\Presenter; use Nette\Security\AuthenticationException; final class SignPresenter extends Presenter { /** @var FacebookLogin @inject */ public $facebookLogin; public function actionFacebook() { // Redirect to FB and ask customer to grant access to his account $url = $this->facebookLogin->getLoginUrl($this->link('//facebookAuthorize'), ['email', 'public_profile']); $this->sendResponse(new RedirectResponse($url)); } /** * Log in user with accessToken obtained after redirected from FB * * @return void */ public function actionFacebookAuthorize() { // Fetch User data from FB and try to login try { $token = $this->facebookLogin->getAccessToken(); $this->user->login('facebook', $this->facebookLogin->getMe($token->getValue(), ['first_name', 'last_name', 'email', 'gender'])); $this->flashMessage('Login successful :-).', 'success'); } catch (FacebookLoginException | AuthenticationException $e) { $this->flashMessage('Login failed. :-( Try again.', 'danger'); } } }
If you need to specify your own state param (more info here mind also checking Enable Strict Mode). Facebook::getLoginUrl() takes optional third parameter $stateParam which FB passes back unchanged.
JavaScript Login
You can also use FB login button, for example:
<div class="fb-login-button" onlogin="fbAfterLogin()" data-width="200" data-max-rows="1" data-size="medium" data-button-type="continue_with" data-show-faces="false" data-auto-logout-link="false" data-use-continue-as="true" data-scope="email,public_profile" > Login </div>
And use onlogin event to call backend code which takes care of registration/login process:
/** * Log in user with accessToken from cookie/session after javascript authorization */ public function actionFacebookCookie() { // Fetch User data from FB and try to login try { $token = $this->facebookLogin->getAccessTokenFromCookie(); $this->user->login('facebook', $this->facebookLogin->getMe($token, ['first_name', 'last_name', 'email', 'gender'])); $this->flashMessage('Login successful :-).', 'success'); } catch (FacebookLoginException | AuthenticationException $e) { $this->flashMessage('Login failed. :-( Try again.', 'danger'); } }
Versions
| State | Version | Branch | Nette | PHP |
|---|---|---|---|---|
| dev | ^0.4 |
master |
3.0+ | >=7.2 |
| stable | ^0.3 |
master |
3.0+ | ^7.2 |
| stable | ^0.2 |
master |
2.4 | >=7.1 |
Development
This package was maintained by these authors.
Consider to support contributte development team. Also thank you for using this package.