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

Oauth Bundle Laravel Package

hwi/oauth-bundle

Symfony bundle for OAuth1.0a/OAuth2 login and user authentication. Supports Symfony 6.4–8.0 (PHP 8.3+) and integrates dozens of providers (Google, GitHub, Facebook, Apple, LinkedIn, Azure, Keycloak, etc.).

View on GitHub
Deep Wiki
Context7

Bonus: Facebook Connect

Configuration

Configuration of the Resource Owner

# config/packages/hwi_oauth.yaml
hwi_oauth:
    resource_owners:
        facebook:
            type:          facebook
            client_id:     <client_id>
            client_secret: <client_secret>
            scope:         "email"
            options:
                display: popup #dialog is optimized for popup window

services:
    hwi_oauth.user.provider.entity:
        class: HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider

Import Routing

# app/config/routing.yml

hwi_oauth_redirect:
    resource: "[@HWIOAuthBundle](https://github.com/HWIOAuthBundle)/Resources/config/routing/redirect.php"
    prefix:   /demo/secured/connect

facebook_login:
    path: /demo/secured/login_facebook

Configuration of the Security Layer

# config/packages/security.yaml

firewalls:
    # ...
    main:
        pattern: ^/demo/secured/
        oauth:
            resource_owners:
                facebook:      /demo/secured/login_facebook
            login_path:        /demo/secured/login
            failure_path:      /demo/secured/login
            oauth_user_provider:
                service: hwi_oauth.user.provider.entity

    access_control:
      # Turn on anonymous for testings need.
      - { path: ^/login, roles: PUBLIC_ACCESS }

Adding the Facebook Login Button

The following example bases also on the Facebook "Login with Javascript SDK" guide.

# templates/Secured/hello.html.twig

{% block content %}
    <div id="fb-root"></div>
    <script>
        window.fbAsyncInit = function() {
            // init the FB JS SDK
            FB.init({
                appId      : '12345678910',                        // App ID from the app dashboard
                channelUrl : '//yourdomain.com/channel.html',      // Channel file for x-domain comms
                status     : true,                                 // Check Facebook Login status
                xfbml      : true                                  // Look for social plugins on the page
            });
        };

        // Load the SDK asynchronously
        (function(d, s, id){
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));

        function fb_login() {
            FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {
                    // connected
                    alert('Already connected, redirect to login page to create token.');
                    document.location = "{{ url("hwi_oauth_service_redirect", {service: "facebook"}) }}";
                } else {
                    // not_authorized
                    FB.login(function(response) {
                        if (response.authResponse) {
                            document.location = "{{ url("hwi_oauth_service_redirect", {service: "facebook"}) }}";
                        } else {
                            alert('Cancelled.');
                        }
                    }, {scope: 'email'});
                }
            });
        }
    </script>

    <h1 class="title">Hello {{ name }}!</h1>

    <a href="{{ path('_demo_secured_hello_admin', { 'name': name }) }}">Hello resource secured for <strong>admin</strong> only.</a>

    <p>
        <a href="#" onclick="fb_login();">Facebook Connect Button (Dialog)</a>
    </p>

    {# Bonus: Show all available login link in HWIOAuthBundle #}
    {% render(controller('HWI\\Bundle\\OAuthBundle\\Controller\\LoginController::connectAction')) %}
{% endblock %}

Make sure {scope: 'email'} is added as the second argument to FB.login. Or elsewhere, you would have to prompt the user with the authentication for the basic data, and then ask him again to accept that you need his email.

Watch the results!

Open the browser and go to /demo/secured/hello/World to view and test the login button!

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.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php