Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
added google+ oauth 2 example, and updated readme
Browse files Browse the repository at this point in the history
added google+ oauth 2 example
updated readme
minor fixes
  • Loading branch information
chrisweb committed Apr 15, 2013
1 parent 6a92b4d commit d20e329
Show file tree
Hide file tree
Showing 18 changed files with 439 additions and 86 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/examples/FacebookOpenGraphOAuth2/nbproject/
/examples/JamendoApiOAuth2/nbproject/
/examples/GooglePlusOAuth2/nbproject/
/examples/FacebookOpenGraphOAuth2/application/configs/facebook_api.ini
/examples/JamendoApiOAuth2/application/configs/jamendo_api.ini
/examples/JamendoApiOAuth2/application/configs/jamendo_api.ini
/examples/GooglePlusOAuth2/application/configs/google_plus_api.ini
76 changes: 70 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ apache vhost.conf
```
; application/configs/jamendo_api.ini
; http://developer.jamendo.com/v3.0/oauth2
; to get a jamendo api account visit: https://devportal.jamendo.com/
; jamendo api configuration
dialogEndpoint = https://api.jamendo.com/v3.0
oauthEndpoint = https://api.jamendo.com/v3.0
clientId = 000000000
clientSecret = 00000000000000000000000000000000
callbackUrl = http://www.mywebsite.dev/jamendocallback
clientId = 0000000000
clientSecret = 0000000000000000000000000000
callbackUrl = http://www.jamendoapioauth2.dev/jamendocallback
oauthDialogUri = /oauth/authorize
accessTokenUri = /oauth/grant
stateSecret = a_secret_phrase
stateSecret = afs4f4g8e4asgaas
grantType = authorization_code
requestedRights = music ; = scope
responseType = code ; = response_type
```

Facebook Open Graph API OAuth 2
Expand Down Expand Up @@ -98,13 +102,73 @@ apache vhost.conf
```
; application/configs/facebook_api.ini
; https://developers.facebook.com/docs/howtos/login/server-side-login/
; facebook api configuration
dialogEndpoint = https://www.facebook.com
oauthEndpoint = https://graph.facebook.com
clientId = 0000000000000
clientId = 000000000000000000
clientSecret = 000000000000000000000000000000
callbackUrl = http://www.facebookopengraphoauth2.dev/facebookcallback
responseType = code ; or token, none, signed_request
oauthDialogUri = /dialog/oauth
accessTokenUri = /oauth/access_token
stateSecret = a_secret_phrase
stateSecret = afs4f4g8e4asgaas
; permissions https://developers.facebook.com/docs/concepts/login/permissions-login-dialog/
requestedRights = email,user_actions.music,user_likes
```

Google+ API OAuth 2
-------------------------------

1) Add the latest Zend Framework and the Chrisweb library to the library directory.

2) Setup an Apache vhost for the example:

apache vhost.conf

```
<VirtualHost *:80>
ServerName www.googleplusoauth2.dev
DocumentRoot /path/to/examples/GooglePlusOAuth2/public
ErrorLog "logs/googleplusoauth2-error.log"
CustomLog "logs/googleplusoauth2-access.log" combined
SetEnv APPLICATION_ENV "development"
<Directory /path/to/examples/GooglePlusOAuth2/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
```

3) Update your hosts file:

127.0.0.1 www.googleplusoauth2.dev

4) Create a Google+ API account, then create a configuration file and add the values:

```
; application/configs/google_plus_api.ini
; https://developers.google.com/+/api/oauth
; google+ api configuration
dialogEndpoint = https://accounts.google.com/o/oauth2
oauthEndpoint = https://accounts.google.com/o/oauth2
clientId = 0000000000000000.apps.googleusercontent.com
clientSecret = 00000000000000000000000000000
responseType = code ; https://developers.google.com/accounts/docs/OAuth2Login#responsetypeparameter
callbackUrl = http://127.0.0.1/googlepluscallback
secretType =
immediate =
oauthDialogUri = /auth
accessTokenUri = /token
stateSecret = afs4f4g8e4asgaas
; google+ scopes https://developers.google.com/+/api/oauth#scopes
requestedRights = https://www.googleapis.com/auth/plus.login,https://www.googleapis.com/auth/plus.me,https://www.googleapis.com/auth/userinfo.email
```
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public function indexAction()
*/
public function facebookcallbackAction()
{

//Zend_Debug::dump($_GET['code']);
//Zend_Debug::dump($_GET['error_reason']);


$rawCode = $this->_request->getParam('code', null);
$stateParameter = $this->_request->getParam('state', null);
$errorReason = $this->_request->getParam('error_reason', null);
Expand Down
38 changes: 38 additions & 0 deletions examples/GooglePlusOAuth2/application/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Application Bootstrap
*/
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

protected function _initAutoloader()
{

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Chrisweb');

}

protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('HTML5');
}

protected function _initRouting()
{

//Zend_Debug::dump(APPLICATION_PATH.'/configs/routes.ini');
//exit;

$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/routes.ini');
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addConfig($config, 'routes');
Zend_Controller_Front::getInstance()->setRouter($router);

}

}
35 changes: 35 additions & 0 deletions examples/GooglePlusOAuth2/application/configs/application.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
; application/configs/application.ini

[production]
; phpSettings
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

resources.frontController.params.displayExceptions = 0

includePaths.library = APPLICATION_PATH "/../library"

; bootstrap
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

appnamespace = "Application"

; controllers
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

; layout
resources.layout.layoutPath = APPLICATION_PATH "/views/layouts"

; views
resources.view[] =

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
6 changes: 6 additions & 0 deletions examples/GooglePlusOAuth2/application/configs/routes.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

; facebook callback route
routes.googlepluscallback.type = "Zend_Controller_Router_Route_Static"
routes.googlepluscallback.route = "/googlepluscallback"
routes.googlepluscallback.defaults.controller = "index"
routes.googlepluscallback.defaults.action = "googlepluscallback"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* ErrorController
*/
class ErrorController extends Zend_Controller_Action
{

public function errorAction()
{
$errors = $this->_getParam('error_handler');

switch ($errors->type) {

case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
break;

default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
break;

}

$this->view->exception = $errors->exception;
$this->view->request = $errors->request;
$this->view->env = APPLICATION_ENV;

}

}
Loading

0 comments on commit d20e329

Please sign in to comment.