HWIOAuthBundle
repository·master·Indexed 25 days ago
https://github.com/hwi/hwioauthbundleA 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.
What's inside HWIOAuthBundle
- 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.
How to implement a custom Resource Owner
masterIf 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
GenericOAuth2ResourceOwnerorGenericOAuth1ResourceOwner. This allows you to override specific methods (for example,doGetUserInformationRequestto 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. }Setup Genius as a resource owner
masterTo 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_idandclient_secret, configure a resource owner in yourhwi_oauth.yamlconfiguration file. You can assign any name to the resource owner, but thetypemust be set togenius.# config/packages/hwi_oauth.yaml hwi_oauth: resource_owners: any_name: type: genius client_id: <client_id> client_secret: <client_secret>Setup Vkontakte as a resource owner
masterTo 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_oauthconfiguration. You must specify a unique name for the resource owner, set thetypetovkontakte, and provide yourclient_idandclient_secret. You may also need to define the requiredscopebased 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>Setup Bitly as a resource owner
masterTo use Bitly for OAuth authentication, you must first register your application on Bitly to obtain credentials.
- Register your application at http://bitly.com/a/oauth_apps (or follow the Bitly authentication documentation).
- Obtain your
client_idandclient_secret. - Configure the
bitlyresource owner in yourhwi_oauth.yamlconfiguration file using thetype: bitlysetting.
# config/packages/hwi_oauth.yaml hwi_oauth: resource_owners: any_name: type: bitly client_id: <client_id> client_secret: <client_secret>Install HWIOAuthBundle via Composer
masterInstall 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-bundleSetup RunKeeper as a resource owner
masterTo 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_ownersin your configuration. You must specify thetypeasrunkeeperand provide yourclient_idandclient_secret.# config/packages/hwi_oauth.yaml hwi_oauth: resource_owners: any_name: type: runkeeper client_id: <client_id> client_secret: <client_secret>Setup BufferApp as a resource owner
masterTo 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_idandclient_secret, configure the resource owner in your Symfony application by adding a configuration block underhwi_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>Setup 37signals as a resource owner
masterTo use 37signals for OAuth authentication, follow these steps:
- Register your application: Visit https://integrate.37signals.com/ to register your app.
- 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. - Configure HWIOAuthBundle: Add a resource owner of type
37signalsto yourhwi_oauth.yamlconfiguration file using your providedclient_idandclient_secret.
# config/packages/hwi_oauth.yaml hwi_oauth: resource_owners: any_name: type: 37signals client_id: <client_id> client_secret: <client_secret>Configure a custom Resource Owner
masterOnce you have created your custom Resource Owner class, register it in your
resource_ownersconfiguration. You must specify thetype(e.g.,oauth2), the fully qualified class name in theclasskey, 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%'Setup Foursquare as a resource owner
masterTo 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.yamlconfiguration file. You must set thetypetofoursquareand provide yourclient_idandclient_secret.# config/packages/hwi_oauth.yaml hwi_oauth: resource_owners: any_name: type: foursquare client_id: <client_id> client_secret: <client_secret>Setup Twitter as a resource owner
masterTo use Twitter for authentication, you must first register your application on the Twitter Developer Portal.
Required Twitter Settings:
- Set up a callback URL in your Twitter application settings.
- 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
twittertype and providing yourclient_idandclient_secret.# config/packages/hwi_oauth.yaml hwi_oauth: resource_owners: any_name: type: twitter client_id: <consumer-key> client_secret: <consumer-secret>