PHPackages                             stavarengo/o-auth-connect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. stavarengo/o-auth-connect

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

stavarengo/o-auth-connect
=========================

The easiest way to connect to OAuth2 services using Zend Framework 2 (ZF2)

v0.0.9(7y ago)041BSD-3-ClausePHPPHP ^5.5|~7.0

Since Jul 15Pushed 6y agoCompare

[ Source](https://github.com/stavarengo/o-auth-connect)[ Packagist](https://packagist.org/packages/stavarengo/o-auth-connect)[ RSS](/packages/stavarengo-o-auth-connect/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (10)Used By (0)

o-auth-connect
==============

[](#o-auth-connect)

OAuthConnect is a ZF2/ZF3 library that adds the "Login With Facebook, Google, etc" behavior to you application.

It's a tiny ZF2 module that you can require using composer. It does not install any tirdy part OAuth library automatically, so you are free to install only the OAuth librarys of the services you want to use and o-auth-connect will detect it.

For example. Lets say you want add Login With Facebook functionality to your site. In order to do that you just need to install o-auth-connect and then install [Facebook PHP SDK](https://developers.facebook.com/docs/reference/php/). That way you only install what you will be using.

Installing
----------

[](#installing)

1. Execute `composer require stavarengo/o-auth-connect:^0.0`
2. Install all libraries of the OAuth Services you want to use. See [list of supported services](#supported-oauth-services).

Using it
--------

[](#using-it)

### First Things First: Concepts!

[](#first-things-first-concepts)

The simplier the better. With OAuthConnect you just have tow URLs to work with, instead of worry about all the URLs endpoint that each OAuth service expose to you interact with when asking for someone's authorization.

1. `sta/oAuthConnect/ask/:oAuthService`: This route is to where you must send your users when asking for their authorizations. This route renders a URL like this: `/sta/o-auth-connect/facebook`.
2. `sta/oAuthConnect/response`: This is where the OAuth Service will redirect the users autorization's response. Most of the OAuth Services ask for an *redirect callback URL*. This is an URL in your site that is prepared to receive the user's authorization response (if the user allow or deny your request). OAuthConnect take care of the response for your, so whenever you were setting up a OAuth Service account and it asks you something like "Whats your redirect URL?", you must set `/sta/o-auth-connect/response`. Later int this file you will see how to listen to that response.

### Learn by Example

[](#learn-by-example)

Lest see how it works with an example. In this example we are going to add "Login With Facebook" and "Login with Google" functionality to our site.

#### Learn by Example: Showing links to login

[](#learn-by-example-showing-links-to-login)

First you need to add the links that says "Login with Facebook" and "Login with Google". These links will point to the route `sta/oAuthConnect/ask/:oAuthService`. So, put the code bellow inside a Zend View (the `phtml` file) that will print out the links (Note: This code will fail! If you're in a hurry [skip to here](#executing-and-testing), otherwise, continue to read to see why it will fail).

```
