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

Commit d20e329

Browse files
committed
added google+ oauth 2 example, and updated readme
added google+ oauth 2 example updated readme minor fixes
1 parent 6a92b4d commit d20e329

File tree

18 files changed

+439
-86
lines changed

18 files changed

+439
-86
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/examples/FacebookOpenGraphOAuth2/nbproject/
22
/examples/JamendoApiOAuth2/nbproject/
3+
/examples/GooglePlusOAuth2/nbproject/
34
/examples/FacebookOpenGraphOAuth2/application/configs/facebook_api.ini
4-
/examples/JamendoApiOAuth2/application/configs/jamendo_api.ini
5+
/examples/JamendoApiOAuth2/application/configs/jamendo_api.ini
6+
/examples/GooglePlusOAuth2/application/configs/google_plus_api.ini

README.md

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ apache vhost.conf
4747
```
4848
; application/configs/jamendo_api.ini
4949
50+
; http://developer.jamendo.com/v3.0/oauth2
51+
5052
; to get a jamendo api account visit: https://devportal.jamendo.com/
5153
5254
; jamendo api configuration
5355
dialogEndpoint = https://api.jamendo.com/v3.0
5456
oauthEndpoint = https://api.jamendo.com/v3.0
55-
clientId = 000000000
56-
clientSecret = 00000000000000000000000000000000
57-
callbackUrl = http://www.mywebsite.dev/jamendocallback
57+
clientId = 0000000000
58+
clientSecret = 0000000000000000000000000000
59+
callbackUrl = http://www.jamendoapioauth2.dev/jamendocallback
5860
oauthDialogUri = /oauth/authorize
5961
accessTokenUri = /oauth/grant
60-
stateSecret = a_secret_phrase
62+
stateSecret = afs4f4g8e4asgaas
6163
grantType = authorization_code
64+
requestedRights = music ; = scope
65+
responseType = code ; = response_type
6266
```
6367

6468
Facebook Open Graph API OAuth 2
@@ -98,13 +102,73 @@ apache vhost.conf
98102
```
99103
; application/configs/facebook_api.ini
100104
105+
; https://developers.facebook.com/docs/howtos/login/server-side-login/
106+
101107
; facebook api configuration
102108
dialogEndpoint = https://www.facebook.com
103109
oauthEndpoint = https://graph.facebook.com
104-
clientId = 0000000000000
110+
clientId = 000000000000000000
105111
clientSecret = 000000000000000000000000000000
106112
callbackUrl = http://www.facebookopengraphoauth2.dev/facebookcallback
113+
responseType = code ; or token, none, signed_request
107114
oauthDialogUri = /dialog/oauth
108115
accessTokenUri = /oauth/access_token
109-
stateSecret = a_secret_phrase
116+
stateSecret = afs4f4g8e4asgaas
117+
; permissions https://developers.facebook.com/docs/concepts/login/permissions-login-dialog/
118+
requestedRights = email,user_actions.music,user_likes
119+
```
120+
121+
Google+ API OAuth 2
122+
-------------------------------
123+
124+
1) Add the latest Zend Framework and the Chrisweb library to the library directory.
125+
126+
2) Setup an Apache vhost for the example:
127+
128+
apache vhost.conf
129+
130+
```
131+
<VirtualHost *:80>
132+
133+
ServerName www.googleplusoauth2.dev
134+
DocumentRoot /path/to/examples/GooglePlusOAuth2/public
135+
ErrorLog "logs/googleplusoauth2-error.log"
136+
CustomLog "logs/googleplusoauth2-access.log" combined
137+
SetEnv APPLICATION_ENV "development"
138+
139+
<Directory /path/to/examples/GooglePlusOAuth2/public>
140+
DirectoryIndex index.php
141+
AllowOverride All
142+
Order allow,deny
143+
Allow from all
144+
</Directory>
145+
146+
</VirtualHost>
147+
```
148+
149+
3) Update your hosts file:
150+
151+
127.0.0.1 www.googleplusoauth2.dev
152+
153+
4) Create a Google+ API account, then create a configuration file and add the values:
154+
155+
```
156+
; application/configs/google_plus_api.ini
157+
158+
; https://developers.google.com/+/api/oauth
159+
160+
; google+ api configuration
161+
dialogEndpoint = https://accounts.google.com/o/oauth2
162+
oauthEndpoint = https://accounts.google.com/o/oauth2
163+
clientId = 0000000000000000.apps.googleusercontent.com
164+
clientSecret = 00000000000000000000000000000
165+
responseType = code ; https://developers.google.com/accounts/docs/OAuth2Login#responsetypeparameter
166+
callbackUrl = http://127.0.0.1/googlepluscallback
167+
secretType =
168+
immediate =
169+
oauthDialogUri = /auth
170+
accessTokenUri = /token
171+
stateSecret = afs4f4g8e4asgaas
172+
; google+ scopes https://developers.google.com/+/api/oauth#scopes
173+
requestedRights = https://www.googleapis.com/auth/plus.login,https://www.googleapis.com/auth/plus.me,https://www.googleapis.com/auth/userinfo.email
110174
```

examples/FacebookOpenGraphOAuth2/application/controllers/IndexController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ public function indexAction()
5757
*/
5858
public function facebookcallbackAction()
5959
{
60-
61-
//Zend_Debug::dump($_GET['code']);
62-
//Zend_Debug::dump($_GET['error_reason']);
63-
60+
6461
$rawCode = $this->_request->getParam('code', null);
6562
$stateParameter = $this->_request->getParam('state', null);
6663
$errorReason = $this->_request->getParam('error_reason', null);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* Application Bootstrap
5+
*/
6+
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
7+
{
8+
9+
protected function _initAutoloader()
10+
{
11+
12+
$autoloader = Zend_Loader_Autoloader::getInstance();
13+
$autoloader->registerNamespace('Chrisweb');
14+
15+
}
16+
17+
protected function _initDoctype()
18+
{
19+
$this->bootstrap('view');
20+
$view = $this->getResource('view');
21+
$view->doctype('HTML5');
22+
}
23+
24+
protected function _initRouting()
25+
{
26+
27+
//Zend_Debug::dump(APPLICATION_PATH.'/configs/routes.ini');
28+
//exit;
29+
30+
$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/routes.ini');
31+
$frontController = Zend_Controller_Front::getInstance();
32+
$router = $frontController->getRouter();
33+
$router->addConfig($config, 'routes');
34+
Zend_Controller_Front::getInstance()->setRouter($router);
35+
36+
}
37+
38+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; application/configs/application.ini
2+
3+
[production]
4+
; phpSettings
5+
phpSettings.display_startup_errors = 0
6+
phpSettings.display_errors = 0
7+
8+
resources.frontController.params.displayExceptions = 0
9+
10+
includePaths.library = APPLICATION_PATH "/../library"
11+
12+
; bootstrap
13+
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
14+
bootstrap.class = "Bootstrap"
15+
16+
appnamespace = "Application"
17+
18+
; controllers
19+
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
20+
21+
; layout
22+
resources.layout.layoutPath = APPLICATION_PATH "/views/layouts"
23+
24+
; views
25+
resources.view[] =
26+
27+
[staging : production]
28+
29+
[testing : production]
30+
phpSettings.display_startup_errors = 1
31+
phpSettings.display_errors = 1
32+
33+
[development : production]
34+
phpSettings.display_startup_errors = 1
35+
phpSettings.display_errors = 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
; facebook callback route
3+
routes.googlepluscallback.type = "Zend_Controller_Router_Route_Static"
4+
routes.googlepluscallback.route = "/googlepluscallback"
5+
routes.googlepluscallback.defaults.controller = "index"
6+
routes.googlepluscallback.defaults.action = "googlepluscallback"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* ErrorController
5+
*/
6+
class ErrorController extends Zend_Controller_Action
7+
{
8+
9+
public function errorAction()
10+
{
11+
$errors = $this->_getParam('error_handler');
12+
13+
switch ($errors->type) {
14+
15+
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
16+
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
17+
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
18+
19+
// 404 error -- controller or action not found
20+
$this->getResponse()->setHttpResponseCode(404);
21+
$this->view->message = 'Page not found';
22+
break;
23+
24+
default:
25+
// application error
26+
$this->getResponse()->setHttpResponseCode(500);
27+
$this->view->message = 'Application error';
28+
break;
29+
30+
}
31+
32+
$this->view->exception = $errors->exception;
33+
$this->view->request = $errors->request;
34+
$this->view->env = APPLICATION_ENV;
35+
36+
}
37+
38+
}

0 commit comments

Comments
 (0)