In the previous part of this series, we created our initial interfaces which we’ll be using for all future parts. In this article, we will integrate Google+ within our application.
You can view the code for all the articles on this Github page.
Google+ login
We start off by creating the following directory: src/SitePoint/SocialLogin/Google
. This will be the directory we will be working in for the rest of the article. Within this directory, we create the GoogleLogin
class. This class implements the SocialLoginInterface
interface which we created in the previous article. Make sure a property called service
is available to store our service in (see code below).
Google has some specific needs to make sure we can log in. So make sure we have the following 3 properties present in the class:
- client id
- key
- callback URL
Since all 3 properties are required for our application to work, our constructor will receive these 3 variables as parameters and set the properties.
Until now, our code looks like this.
<?php
namespace SitePoint\SocialLogin\Google;
use SitePoint\SocialLogin\Interfaces\SocialLoginInterface;
class GoogleLogin implements SocialLoginInterface {
/**
* Google service
*
* @var string
*/
protected $service;
/**
* OAuth client ID
*
* @var string
*/
protected $clientId;
/**
* OAuth key
*
* @var string
*/
protected $key;
/**
* Callback url
*
* @var string
*/
protected $callbackUrl;
/**
* Constructor
*
* @param $clientId string
* @param $key string
* @param $callbackUrl string
*/
public function __construct($clientId, $key, $callbackUrl)
{
$this->clientId = $clientId;
$this->key = $key;
$this->callbackUrl = $callbackUrl;
}
/**
* Initializes our service
*/
public function init()
{
}
/**
* Returns the login url for the social network
*
* @return string
*/
public function getLoginUrl()
{
Truncated by Planet PHP, read more at the original (another 1072 bytes)
more
{ 0 comments... » Social Network Authentication: Google+ read them below or add one }
Post a Comment