Giter VIP home page Giter VIP logo

oauth2facebookgrantbundle's Introduction

FSCOAuth2FacebookGrantBundle

With this bundle, you can request an access token on your api (that uses FOSOAuthServerBundle) against a facebook access token. This bundle will check that the facebook access token is valid, and get the fb_id of the user.

For example: you have an iOS app that needs a token to authenticate a user against your api, but you want to only show the Facebook SSO authentication to your user.

Installation

Add the bundle to your AppKernel

class AppKernel extends Kernel
    public function registerBundles()
        {
            $bundles = array(
                ...
                new AdrienBrault\OAuth2FacebookGrantBundle\ABOAuth2FacebookGrantBundle(),

Configure the bundle:

ab_oauth2_facebook_grant:
    user_provider: bundle.facebook_user_provider
    uri: "http://grants.yourapi.com/facebook_access_token"

And implement your bundle.facebook_user_provider like this:

<?php

namespace AdrienBrault\Core\UserBundle\Security;

use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;

use FSC\Core\UserBundle\Manager\UserManager;

class FacebookUserProvider implements UserProviderInterface
{
    protected $userManager;

    public function __construct(UserManager $userManager)
    {
        $this->userManager = $userManager;
    }

    public function loadUserByUsername($facebookId)
    {
        $userRepository = $this->userManager->getRepository();

        return $userRepository->findOneBy(array(
            'facebookID' => $facebookId,
        ));
    }

    public function refreshUser(UserInterface $user)
    {
        $class = get_class($user);
        if (!$this->supportsClass($class)) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class));
        }

        return $this->loadUserByUsername($user->getFacebookID());
    }

    public function supportsClass($class)
    {
        return $this->userManager->supportsClass($class);
    }
}

Usage

Endpoint: /oauth/v2/token by default

Parameters:

 - client_id
 - client_secret
 - facebook_access_token

Example

$ curl -XGET "http://youapi/oauth/v2/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=http%3A%2F%2Fgrants.yourapi.com%2Ffacebook_access_token&facebook_access_token=A_VALID_FACEBOOK_ACCESS_TOKEN"
{
    "access_token": "krXC75SKp--cISB_fqHA4aSsviyDVJwuutiWgaM",
    "expires_in": 604800,
    "token_type": "bearer",
    "scope": null,
    "refresh_token": "mnFs3VsGIF87x6VIazAz5ftvYw7VTfRqoBSqNCY"
}

oauth2facebookgrantbundle's People

Contributors

adrienbrault avatar ludofleury avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.