This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Bug fixes and improved MyGlass 'off' handling #6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
// found at https://developers.google.com/glass/v1/reference | ||
|
||
require_once 'config.php'; | ||
require_once 'google-api-php-client/src/Google_Client.php'; | ||
require_once 'google-api-php-client/src/contrib/Google_Oauth2Service.php'; | ||
|
||
// Returns an unauthenticated service | ||
function get_google_api_client() { | ||
|
@@ -49,6 +51,38 @@ function get_google_api_client() { | |
return $client; | ||
} | ||
|
||
/* | ||
* Verify the credentials. If they're broken, attempt to re-auth | ||
* This will only work if you haven't printed anything yet (since | ||
* it uses an HTTP header for the redirect) | ||
*/ | ||
function verify_credentials($credentials) { | ||
//TODO: Use the oauth2.tokeninfo() method instead once it's | ||
// exposed by the PHP client library | ||
global $base_url; | ||
|
||
$client = get_google_api_client(); | ||
$client->setAccessToken($credentials); | ||
|
||
$token_checker = new Google_Oauth2Service($client); | ||
try { | ||
$token_checker->userinfo->get(); | ||
} catch (Google_ServiceException $e) { | ||
if($e->getCode() == 401) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/if(/if (/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done :) |
||
// This user may have disabled the Glassware on MyGlass. | ||
// Clean up the mess and attempt to re-auth. | ||
unset($_SESSION['userid']); | ||
header('Location: ' . $base_url . '/oauth2callback.php'); | ||
exit; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra empty line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} else { | ||
// Let it go... | ||
throw $e; | ||
} | ||
} | ||
|
||
} | ||
|
||
function insert_timeline_item($service, $timeline_item, $content_type, $attachment) | ||
{ | ||
try { | ||
|
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space before TODO and re-indent accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done