Developed with love by KnpLabs Hire us for your project!
72

KnpOAuthBundle

by KnpLabs

You should probably use HWIOAuthBundle (https://github.com/hwi/HWIOAuthBundle) instead, though. -- THIS PROJECT IS NO LONGER MAINTAINED by KnpLabs

This project is no longer maintained by KnpLabs

Use HWIOAuthBundle instead

KnpOAuthBundle, an OAuth firewall for Symfony2

Instructions for 2.1 branch

Please note this is the 2.1 compatible branch of this bundle. If you are using Symfony 2.0.*, then you should upgrade. If you can't, you can still use the 2.0 branch.

Introduction

This bundle provides an OAuth firewall for Symfony2.

You should really read the full documentation, but if you're in a hurry (I know you are), this file should help you quickly getting a working setup.

Requirements

Installation

Add this to your deps:

[Buzz]
    git=https://github.com/kriswallsmith/Buzz.git
    version=v0.5

[BuzzBundle]
    git=https://github.com/sensio/SensioBuzzBundle.git
    target=/bundles/Sensio/Bundle/BuzzBundle

[KnpOAuthBundle]
    git=https://github.com/KnpLabs/KnpOAuthBundle.git
    target=/bundles/Knp/Bundle/OAuthBundle

Then run the usual bin/vendors:

bin/vendors install

Register autoloads:

$loader->registerNamespaces(array(
    'Knp'              => __DIR__.'/../vendor/bundles',
    'Buzz'             => __DIR__.'/../vendor/Buzz/lib'
));

Register the bundles in your AppKernel:

$bundles = array(
    new Knp\Bundle\OAuthBundle\KnpOAuthBundle(),
    new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(),
);

Configuration

Using the KnpOAuthBundle is just a matter of configuring an oauth firewall in your security.yml. The bundle exposes a number of configuration directives to suit your oauth needs. Here's a pretty standard security configuration:

security:
    firewalls:
        login:
            pattern:    ^/secured/login$
            security:   false
        secured_area:
            pattern:    ^/secured/
            oauth:
                oauth_provider:    oauth
                authorization_url: https://github.com/login/oauth/authorize
                access_token_url:  https://github.com/login/oauth/access_token
                infos_url:         https://github.com/api/v2/json/user/show
                username_path:     user.login
                client_id:         <your_oauth_client_id>
                secret:            <your_oauth_secret>
                scope:             <your_oauth_scope>
                check_path:        /secured/login_check
                login_path:        /secured/login

Please see the configuration reference for a description of the configuration options.

Right now, what you probably want to know is that this bundle comes with a few pre-configured oauth provider, namely:

  • github (required options: client_id, secret)
  • er... that's all for now.

If you don't see your favorite provider in the list, don't worry, there are three solutions, depending on how much of a hurry you're in:

  1. Implement it (and it would be awesome if you contributed it afterwards)
  2. Use the generic OAuth provider
  3. Ask us to implement it. (please provide as much information as possible (authorize_url, access_token_url, infos_url (with its response format) and username_path would be nice))

User providers

Most of the time, if you are using Doctrine, you will want to use the EntityUserProvider.

This provider fetches users from the database and creates them on the fly if they don't already exist. It requires Doctrine to work. It works exactly like Doctrine's entity user provider, except its configuration key is oauth_entity:

providers:
    secured_area:
        oauth_entity:
            class: KnpBundlesBundle:User
            property: name
Copyright (c) 2011 KnpLabs - http://www.knplabs.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission 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.
  • Mention in README file that this bundle is no longer maintained
    By stloyd, 1 year ago
  • Fix composer.json syntax
    By mbontemps, 2 years ago
  • Merge pull request #18 from asm89/fix_undef_class_constant
    By ubermuda, 2 years ago
  • self:: -> HttpRequest::
    By asm89, 2 years ago
  • dropped custom sensio/buzz-bundle composer repo and updated contributors in composer.json
    By ubermuda, 2 years ago
  • Added missing use statement in GoogleProvider
    By ubermuda, 2 years ago
  • google provider (untested)
    By ubermuda, 2 years ago
  • removed useless namespace
    By ubermuda, 2 years ago
  • fixed invalid namespace for OAuthUser in OAuthUserProvider class
    By ubermuda, 2 years ago
  • Merge pull request #10 from marijn/patch-1
    By ubermuda, 2 years ago
  • Fixed incorrect configuration key.
    By marijn, 2 years ago
  • added missing private $em
    By ubermuda, 2 years ago
  • facebook breaks the oauth spec, too
    By ubermuda, 2 years ago
  • Facebook OAuth provider
    By ubermuda, 2 years ago
  • Quick fix for entity user provider
    By ubermuda, 2 years ago
  • Merge pull request #3 from gimler/patch-1
    By ubermuda, 2 years ago
  • authorization_url not authorize_url
    By gimler, 2 years ago
  • fixed direct auth attempts on login_path
    By ubermuda, 2 years ago
  • throw an exception when unable to follow username_path
    By ubermuda, 2 years ago
  • also fixed default username_path for github provider
    By ubermuda, 2 years ago
  • typo in README
    By ubermuda, 2 years ago
  • updated README
    By ubermuda, 2 years ago
  • Revert "Update README.md"
    By ubermuda, 2 years ago
  • Update README.md
    By stloyd, 2 years ago
  • [GitHub] Use API v3 URL for accessing user data
    By stloyd, 2 years ago
  • Use more correct exception class
    By stloyd, 2 years ago
  • Sync with latest Symfony 2.1 changes
    By stloyd, 2 years ago
  • full-fledged doc example was missing a providers section
    By ubermuda, 2 years ago
  • removed reference about DIC Extensions since it's not needed
    By ubermuda, 2 years ago
  • fixed symfony version in composer.json
    By ubermuda, 2 years ago