Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Fbbundle Laravel Package

edemy/fbbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require masando/edemy-fbbundle
    

    Register the bundle in config/bundles.php (if using Symfony-style bundles):

    return [
        // ...
        Masando\eDemyFbBundle\eDemyFbBundle::class => ['all' => true],
    ];
    
  2. Configuration Publish the default config:

    php artisan vendor:publish --provider="Masando\eDemyFbBundle\eDemyFbBundle" --tag="config"
    

    Update config/edemy_fb.php with your Facebook App credentials (App ID, Secret, etc.).

  3. First Use Case: Login with Facebook Add the login route to your routes/web.php:

    use Masando\eDemyFbBundle\Routing\FacebookController;
    
    Route::get('/login/facebook', [FacebookController::class, 'login']);
    Route::get('/login/facebook/callback', [FacebookController::class, 'callback']);
    

    Use the FacebookAuthenticator service in a controller:

    use Masando\eDemyFbBundle\Services\FacebookAuthenticator;
    
    public function handleFacebookLogin(FacebookAuthenticator $authenticator) {
        $user = $authenticator->authenticate();
        // Handle user (e.g., create/update in DB, redirect)
    }
    

Implementation Patterns

Workflows

  1. Authentication Flow

    • Redirect users to Facebook for OAuth:
      return $authenticator->redirectToFacebook();
      
    • Handle the callback:
      $userData = $authenticator->getUserFromFacebook();
      
    • Map Facebook data to your user model:
      $user = User::updateOrCreate(
          ['email' => $userData['email']],
          [
              'name' => $userData['name'],
              'facebook_id' => $userData['id'],
          ]
      );
      
  2. Graph API Integration Fetch user data or publish actions:

    use Masando\eDemyFbBundle\Services\FacebookGraph;
    
    public function fetchUserPosts(FacebookGraph $graph, $userId) {
        return $graph->get('/' . $userId . '/posts');
    }
    
  3. Webhooks Configure webhooks in config/edemy_fb.php:

    'webhooks' => [
        'verify_token' => 'your_verify_token',
        'callback_url' => '/facebook/webhook',
    ],
    

    Handle events in a controller:

    public function handleWebhook(Request $request, FacebookWebhookHandler $handler) {
        $handler->process($request->input());
    }
    

Integration Tips

  • Laravel-Specific: Use Laravel’s service container to bind the bundle’s services:
    $this->app->bind('facebook.authenticator', function ($app) {
        return new FacebookAuthenticator($app['config']['edemy_fb']);
    });
    
  • Middleware: Protect routes requiring Facebook auth:
    Route::middleware(['auth:facebook'])->group(function () {
        // Protected routes
    });
    
  • Events: Extend the bundle by listening to its events (e.g., FacebookUserAuthenticated).

Gotchas and Tips

Pitfalls

  1. App Secret Mismatch

    • Ensure the app_secret in config/edemy_fb.php matches your Facebook App settings.
    • Debug with: php artisan config:clear if changes aren’t reflected.
  2. Webhook Verification

    • Always validate the hub.challenge and hub.mode in the webhook endpoint to avoid spoofing.
    • Example:
      if ($request->input('hub.mode') !== 'subscribe' || $request->input('hub.challenge')) {
          abort(403);
      }
      
  3. Deprecated API Calls

    • The bundle may use older Graph API versions. Update the default_graph_version in config to v18.0 if needed.
  4. CORS Issues

    • If using the Graph API from the frontend, ensure your Facebook App’s Valid OAuth Redirect URIs include your domain.

Debugging

  • Enable Logging Add to config/edemy_fb.php:

    'debug' => env('APP_DEBUG', false),
    

    Check logs in storage/logs/laravel.log for OAuth errors.

  • Token Expiry Handle expired tokens by implementing a refresh logic:

    try {
        $authenticator->getAccessToken();
    } catch (TokenExpiredException $e) {
        $authenticator->refreshToken();
    }
    

Extension Points

  1. Custom User Mappers Override the default user mapping by binding a custom mapper:

    $this->app->bind('facebook.user_mapper', function () {
        return new CustomFacebookUserMapper();
    });
    
  2. Additional Permissions Extend the default permissions (e.g., email, public_profile) in the config:

    'auth' => [
        'permissions' => ['email', 'public_profile', 'user_birthday'],
    ],
    
  3. Custom Graph API Methods Extend the FacebookGraph service by creating a decorator:

    class CustomFacebookGraph extends FacebookGraph {
        public function customMethod($path) {
            return $this->call('/me/' . $path);
        }
    }
    

    Bind it in a service provider:

    $this->app->bind('facebook.graph', function ($app) {
        return new CustomFacebookGraph($app['config']['edemy_fb']);
    });
    

Config Quirks

  • Environment Variables Prefer using .env for sensitive data:

    FB_APP_ID=your_app_id
    FB_APP_SECRET=your_app_secret
    

    Reference them in config/edemy_fb.php:

    'app_id' => env('FB_APP_ID'),
    'app_secret' => env('FB_APP_SECRET'),
    
  • Default Redirect URI The bundle assumes /login/facebook/callback as the default redirect URI. Update it in config if needed:

    'auth' => [
        'redirect_uri' => '/custom/callback',
    ],
    

    Ensure this URI is also added to your Facebook App’s Valid OAuth Redirect URIs.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor