Skip to content

Instantly share code, notes, and snippets.

@AstDerek
Created May 11, 2012 02:15
Show Gist options
  • Save AstDerek/2657083 to your computer and use it in GitHub Desktop.
Save AstDerek/2657083 to your computer and use it in GitHub Desktop.
Simple OAuth workflow
<?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