Created
May 11, 2012 02:15
-
-
Save AstDerek/2657083 to your computer and use it in GitHub Desktop.
Simple OAuth workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$client_id = GOOGLE_CLIENT_ID; | |
$client_secret = GOOGLE_CLIENT_SECRET; | |
$redirect_uri = GOOGLE_CALLBACK; | |
$google_oauth = new Google_OAuth($client_id,$client_secret,$redirect_uri,'userinfo'); | |
$status = ''; | |
$credentials = FALSE; | |
$errors = array(); | |
/** | |
* First attemp, validate any code from Google | |
*/ | |
if (isset($_REQUEST['code'])) { | |
$credentials = $google_oauth->consume_code($_REQUEST['code']); | |
$errors []= $credentials; | |
if (isset($credentials->email)) { | |
/** | |
* Do something | |
*/ | |
} | |
else { | |
/** | |
* Could not validate the user | |
*/ | |
$status = 'failed'; | |
} | |
} | |
else if (isset($_REQUEST['error'])) { | |
/** | |
* User has denied acces | |
*/ | |
$status = 'denied'; | |
} | |
else { | |
/** | |
* Redirect to Google Authorization page | |
*/ | |
$google_oauth->request_access_code(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment