Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris-B authored Feb 27, 2017
1 parent 0f74038 commit 7e68fdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
19 changes: 9 additions & 10 deletions dist/authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/


// Google OAUTH 2.0 API: https://developers.google.com/identity/protocols/OpenIDConnect

const API_BASE_PATH = 'https://www.googleapis.com';
const OAUTH2_TOKEN_URI = 'https://www.googleapis.com/oauth2/v4/token';
const OAUTH2_AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
// Google OAUTH 2.0 API: https://developers.google.com/identity/protocols/OpenIDConnect
$user_id = '';
$atoken = '';
$rtoken = '';
Expand Down Expand Up @@ -106,8 +106,6 @@
if( $info['http_code'] === 200 ) {
// ok

// header('Content-Type: ' . $info['content_type']);

// retrieve user ID
$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, 'https://picasaweb.google.com/data/feed/api/user/default?access_token=' . $authObj->access_token );
Expand All @@ -130,7 +128,8 @@
$user_id = $objProfile -> id;

if( property_exists( $authObj, 'refresh_token' ) ) {
// refresh token present -> first authorization grant
// refresh token present -> ok, it's the first authorization grant
// store tokens
if( !is_dir( 'admin/users/' . $user_id ) ){
if( @mkdir( 'admin/users/' . $user_id ) === false ) {
$error = error_get_last();
Expand All @@ -147,7 +146,6 @@

// echo 'Authorisation successfully granted.' . PHP_EOL . '<br/>';
response_json( array('nano_status' => 'ok', 'nano_message' => 'Authorisation successfully granted.' ) );
// display_settings();
}
else {
// no refresh token -> authorization has already been granted -> revoke to get a new refresh token
Expand Down Expand Up @@ -176,7 +174,7 @@
// ##########
// REVOKE USER AUTHORIZATION
if( isset($_GET['revoke']) ) {
// can be done manually by the user: https://security.google.com/settings/security/permissions
// can be done manually by the user: https://security.google.com/settings/security/permissions (in this case the user folder remains and must be deleted manually in the admin/users folder)
// but here we can clear also the users data
$user_id = $_GET['revoke'];

Expand All @@ -192,7 +190,7 @@

$atoken=file_get_contents( 'admin/users/' . $user_id . '/token_a.txt');
if( $atoken === false || $atoken == '' ) {
response_json( array('nano_status' => 'error', 'nano_message' => 'could not find access token') );
response_json( array('nano_status' => 'error', 'nano_message' => 'could not find any access token') );
exit;
}

Expand Down Expand Up @@ -233,6 +231,7 @@ function revoke( $user_id ) {
}

response_json( array('nano_status' => 'error', 'nano_message' => 'Error : '. $info['http_code'] . '-' . $ce ) );
exit;
}


Expand All @@ -247,7 +246,7 @@ function revoke( $user_id ) {
}

if( !is_dir( 'admin/users/' . $user_id ) ) {
response_json( array('nano_status' => 'error', 'nano_message' => 'user ID does not exist') );
response_json( array('nano_status' => 'error', 'nano_message' => 'user '. $user_id .' does not exist') );
exit;
}

Expand All @@ -266,10 +265,10 @@ function revoke( $user_id ) {
response_json( array('nano_status' => 'ok', 'nano_message' => 'authorization already granted') );
}





// ##########
// Display connection info for nanogallery2
function display_settings() {
global $user_id, $prot;

Expand Down
5 changes: 2 additions & 3 deletions dist/nanogp.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
set_globals();

$request=$_GET;
// echo implode($request);
// echo implode($request);

$user_id=$request['nguserid'];
unset($request['nguserid']);
Expand Down Expand Up @@ -71,7 +71,6 @@

// ##### retrieve the content of one album
if( $content_kind == 'photo' ) {
// $url = 'https://picasaweb.google.com/data/feed/api/user/' . $user_id . '/albumid/' . $album_id . '?access_token=' . $atoken . '&' . $nq;
$url = 'https://picasaweb.google.com/data/feed/api/user/' . $user_id . '/albumid/' . $album_id;

if( send_gprequest( $url ) === 'token_expired') {
Expand All @@ -82,14 +81,14 @@
}
}


// ##### send the request to picasa/google photos
function send_gprequest( $url ) {
global $callback, $atoken, $request;

$request['access_token']=$atoken;

$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $url . urlencode('&access_token=' . $atoken) );
$url = $url . '?' . http_build_query($request);
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HEADER, false);
Expand Down

0 comments on commit 7e68fdd

Please sign in to comment.