HWIOAuthBundle

repository·master·Indexed 25 days ago

https://github.com/hwi/hwioauthbundle

A Symfony bundle that simplifies the implementation of OAuth1.0a and OAuth2 authentication providers. It includes built-in support for 59 different providers, such as GitHub, Google, and Facebook. The bundle provides tools for configuring resource owners, managing the security layer via OAuth-aware user providers, and implementing a registration 'connect' layer using the AccountConnectorInterface and RegistrationFormHandlerInterface.

Tokens
30.7K
Snippets
110
Records
125
Agent score
82%

What's inside HWIOAuthBundle

  1. Overview of HWIOAuthBundle capabilities

    master
    HWIOAuthBundle provides a streamlined way to implement OAuth1.0a or OAuth2 authentication providers within a Symfony application. It includes built-in support for 59 different providers, allowing developers to easily integrate with major services like GitHub, Google, Facebook, and many others without writing custom authentication logic from scratch.
  2. How to implement a custom Resource Owner

    master

    If a provider does not strictly follow OAuth1 or OAuth2 standards, you can implement a custom Resource Owner in your own project instead of relying on the built-in ones.

    To do this, create a class in your project that extends either GenericOAuth2ResourceOwner or GenericOAuth1ResourceOwner. This allows you to override specific methods (for example, doGetUserInformationRequest to modify header names) to accommodate the specific requirements of your provider.

    use HWIundle\
    OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
    use Psr\Http\Message\RequestInterface;
    use Symfony\Component\OptionsResolver\OptionsResolver;
    
    use HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\GenericOAuth2ResourceOwner;
    
    final class YourResourceOwner extends GenericOAuth2ResourceOwner
    {
        // Your resource owner code here.
    }
  3. Setup Genius as a resource owner

    master

    To use Genius for OAuth authentication, you must first register your application on the Genius developer portal to obtain your credentials.

    Once you have your client_id and client_secret, configure a resource owner in your hwi_oauth.yaml configuration file. You can assign any name to the resource owner, but the type must be set to genius.

    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                genius
                client_id:           <client_id>
                client_secret:       <client_secret>
  4. Setup Vkontakte as a resource owner

    master

    To use Vkontakte for OAuth authentication, you must first register your application on the Vkontakte developer portal.

    Once registered, configure a resource owner in your hwi_oauth configuration. You must specify a unique name for the resource owner, set the type to vkontakte, and provide your client_id and client_secret. You may also need to define the required scope based on the Vkontakte permissions documentation.

    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                vkontakte
                client_id:           <client_id>
                client_secret:       <client_secret>
  5. Setup Bitly as a resource owner

    master

    To use Bitly for OAuth authentication, you must first register your application on Bitly to obtain credentials.

    1. Register your application at http://bitly.com/a/oauth_apps (or follow the Bitly authentication documentation).
    2. Obtain your client_id and client_secret.
    3. Configure the bitly resource owner in your hwi_oauth.yaml configuration file using the type: bitly setting.
    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                bitly
                client_id:           <client_id>
                client_secret:       <client_secret>
  6. Install HWIOAuthBundle via Composer

    master

    Install the bundle using Composer. If you are using a recent version of Symfony with Symfony Flex, accept the recipes from the contrib repository when prompted.

    Note: You may see an error at the end of the installation process; this is expected. You can resolve it by proceeding to the resource owner configuration step.

    composer require hwi/oauth-bundle
  7. Setup RunKeeper as a resource owner

    master

    To integrate RunKeeper authentication, first register your application on the RunKeeper developer portal to obtain your credentials.

    Once registered, configure a resource owner in your Symfony application by adding a entry under hwi_oauth.resource_owners in your configuration. You must specify the type as runkeeper and provide your client_id and client_secret.

    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                runkeeper
                client_id:           <client_id>
                client_secret:       <client_secret>
  8. Setup BufferApp as a resource owner

    master

    To use BufferApp for OAuth authentication, you must first register your application via the BufferApp developer portal to obtain your credentials.

    Once you have your client_id and client_secret, configure the resource owner in your Symfony application by adding a configuration block under hwi_oauth.resource_owners. You can choose any unique name for the resource owner key (e.g., bufferapp).

    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                bufferapp
                client_id:           <client_id>
                client_secret:       <client_secret>
  9. Setup 37signals as a resource owner

    master

    To use 37signals for OAuth authentication, follow these steps:

    1. Register your application: Visit https://integrate.37signals.com/ to register your app.
    2. Set the Redirect URL: Ensure you register the correct redirect URL in the 37signals dashboard. The expected pattern is http://yourproject.com/login/check-37signals. Using an incorrect URL will result in an error.
    3. Configure HWIOAuthBundle: Add a resource owner of type 37signals to your hwi_oauth.yaml configuration file using your provided client_id and client_secret.
    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                37signals
                client_id:           <client_id>
                client_secret:       <client_secret>
  10. Configure a custom Resource Owner

    master

    Once you have created your custom Resource Owner class, register it in your resource_owners configuration. You must specify the type (e.g., oauth2), the fully qualified class name in the class key, and your provider's credentials.

    resource_owners:
        your_provider:
            type:           oauth2
            class:          'Your\Namespace\YourResourceOwner'
            client_id:      '%oauth.your_provider.client_id%'
            client_secret:  '%oauth.your_provider.client_secret%'
            scope:          '%oauth.your_provider.scope%'
  11. Setup Foursquare as a resource owner

    master

    To use Foursquare for OAuth authentication, first register your application on the Foursquare developer portal to obtain your credentials.

    Then, configure a resource owner in your hwi_oauth.yaml configuration file. You must set the type to foursquare and provide your client_id and client_secret.

    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                foursquare
                client_id:           <client_id>
                client_secret:       <client_secret>
  12. Setup Twitter as a resource owner

    master

    To use Twitter for authentication, you must first register your application on the Twitter Developer Portal.

    Required Twitter Settings:

    1. Set up a callback URL in your Twitter application settings.
    2. Enable the option "Allow this application to be used to Sign in with Twitter".

    Once registered, configure a resource owner in your Symfony application using the twitter type and providing your client_id and client_secret.

    # config/packages/hwi_oauth.yaml
    
    hwi_oauth:
        resource_owners:
            any_name:
                type:                twitter
                client_id:           <consumer-key>
                client_secret:       <consumer-secret>