Changeset 28832


Ignore:
Timestamp:
06/29/14 16:09:08 (5 years ago)
Author:
mistic100
Message:

fix oauth flow

Location:
extensions/Google2Piwigo
Files:
13 added
20 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/Google2Piwigo/admin.php

    r26198 r28832  
    1111} 
    1212 
     13// tabsheet 
     14include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); 
     15$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'import'; 
     16 
     17$tabsheet = new tabsheet(); 
     18$tabsheet->add('import', l10n('Import'), PICASA_WA_ADMIN . '-import'); 
     19$tabsheet->add('config', l10n('Configuration'), PICASA_WA_ADMIN . '-config'); 
     20$tabsheet->select($page['tab']); 
     21$tabsheet->assign(); 
     22 
    1323// include page 
    14 include(PICASA_WA_PATH . 'admin/import.php'); 
     24include(PICASA_WA_PATH . 'admin/' . $page['tab'] . '.php'); 
    1525 
    1626// template 
  • extensions/Google2Piwigo/admin/import.php

    r26198 r28832  
    66include_once(PICASA_WA_PATH . 'include/functions.inc.php'); 
    77 
    8 if (!test_remote_download()) 
     8// check API parameters and connect to flickr 
     9if (empty($conf['google2piwigo']['api_key']) or empty($conf['google2piwigo']['secret_key'])) 
     10{ 
     11  $page['warnings'][] = l10n('Please fill your API keys on the configuration tab'); 
     12  $_GET['action'] = 'error'; 
     13} 
     14else if (!test_remote_download()) 
    915{ 
    1016  $page['errors'][] = l10n('No download method available'); 
     
    1824  Zend_Loader::loadClass('Zend_Gdata_AuthSub'); 
    1925  Zend_Loader::loadClass('Zend_Gdata_Photos'); 
     26  require_once('OAuth2/Client.php'); 
     27  require_once('OAuth2/GrantType/AuthorizationCode.php'); 
     28   
     29  $oauth_client = new OAuth2_Client($conf['google2piwigo']['api_key'], $conf['google2piwigo']['secret_key']); 
     30  $oauth_redirect_url = get_absolute_root_url() . PICASA_WA_ADMIN . '-import'; 
    2031   
    2132  // generate token after authentication 
    22   if (!empty($_GET['token'])) 
    23   { 
    24     $_SESSION['gdata_auth_token'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); 
     33  if (!empty($_GET['code'])) 
     34  { 
     35    $params = array('code' => $_GET['code'], 'redirect_uri' => $oauth_redirect_url, 'scope' => 'https://picasaweb.google.com/data/'); 
     36    $response = $oauth_client->getAccessToken($conf['google2piwigo']['token_endpoint'], 'authorization_code', $params); 
     37    $_SESSION['gdata_auth_token'] = $response['result']['access_token']; 
    2538    $_GET['action'] = 'logged'; 
    2639  } 
    2740   
    28   // authentication 
    29   if (empty($_SESSION['gdata_auth_token'])) 
    30   { 
    31     $_GET['action'] = 'login'; 
    32   } 
    33   else 
     41  // must authenticate 
     42  if (!empty($_SESSION['gdata_auth_token'])) 
    3443  { 
    3544    $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['gdata_auth_token']); 
    3645    $picasa = new Zend_Gdata_Photos($client, "Piwigo-Google2Piwigo-1.0"); 
    3746  } 
     47  else 
     48  { 
     49    $params = array('scope' => 'https://picasaweb.google.com/data/'); 
     50    $auth_url = $oauth_client->getAuthenticationUrl($conf['google2piwigo']['auth_endpoint'], $oauth_redirect_url, $params); 
     51    $_GET['action'] = 'init_login'; 
     52  } 
    3853} 
    3954 
     
    4762{ 
    4863  // button to login page 
    49   case 'login': 
    50   { 
    51     $login_url = Zend_Gdata_AuthSub::getAuthSubTokenUri( 
    52       get_absolute_root_url() . PICASA_WA_ADMIN . '-import', 
    53       'https://picasaweb.google.com/data',  
    54       false, true 
    55       ); 
    56          
    57     $template->assign(array( 
    58       'picasa_login' => $login_url, 
    59       'HELP_CONTENT' => load_language('help.lang.html', PICASA_WA_PATH, array('return'=>true)), 
    60       )); 
     64  case 'init_login': 
     65  { 
     66    $template->assign('picasa_login', $auth_url); 
    6167    break; 
    6268  } 
     
    7379  case 'logout': 
    7480  { 
    75     Zend_Gdata_AuthSub::AuthSubRevokeToken( 
    76       $_SESSION['gdata_auth_token'], 
    77       $client 
    78       ); 
    7981    unset($_SESSION['gdata_auth_token']); 
    80      
    8182    $_SESSION['page_infos'][] = l10n('Logged out'); 
    8283    redirect(PICASA_WA_ADMIN . '-import'); 
  • extensions/Google2Piwigo/admin/template/import.tpl

    r27824 r28832  
    1212  window.location.href = "{$picasa_login}"; 
    1313}); 
    14 $(".login_help").click(function() { 
    15   $(".infos.tip").slideToggle(); 
    16 }); 
    1714{/footer_script} 
    1815 
     
    2320 
    2421{* <!-- LOGIN --> *} 
    25 {if $ACTION == 'login'} 
     22{if $ACTION == 'init_login'} 
    2623<p><input type="submit" class="login" value="{'Login'|translate}"></p> 
    27 <p><a href="#" class="login_help">{'Help! I get the error "The site [...] has not been registered."'|translate}</a></p> 
    28  
    29 <div class="infos tip" style="display:none;"> 
    30 {$HELP_CONTENT} 
    31 </div> 
    3224 
    3325{* <!-- MAIN MENU --> *} 
  • extensions/Google2Piwigo/language/en_UK/plugin.lang.php

    r24816 r28832  
    11<?php 
    22 
     3$lang['Please fill your API keys on the configuration tab'] = 'Please fill your API keys on the configuration tab'; 
    34$lang['Successfully logged to you Google account'] = 'Successfully logged to you Google account'; 
    45$lang['One picture is not displayed because already existing in the database.'] = 'One picture is not displayed because already existing in the database.'; 
     
    2425$lang['Geolocalization'] = 'Geolocalization'; 
    2526$lang['Logged in as'] = 'Logged in as'; 
    26 $lang['Help! I get the error "The site [...] has not been registered."'] = 'Help! I get the error "The site [...] has not been registered."'; 
     27$lang['Google project keys'] = 'Google project keys'; 
     28$lang['Callback URL'] = 'Callback URL'; 
     29$lang['How do I get my Google project API key?'] = 'How do I get my Google project API key?'; 
    2730 
    2831?> 
  • extensions/Google2Piwigo/main.inc.php

    r26198 r28832  
    1717define('PICASA_WA_ADMIN', get_root_url() . 'admin.php?page=plugin-' . PICASA_WA_ID); 
    1818define('PICASA_WA_CACHE', PHPWG_ROOT_PATH . $conf['data_location'] . 'picasa_wa_cache/'); 
     19define('PICASA_WA_VERSION',  'auto'); 
    1920 
    2021 
    2122include_once(PICASA_WA_PATH . 'include/ws_functions.inc.php'); 
    2223 
     24 
     25add_event_handler('init', 'picasa_wa_init'); 
    2326add_event_handler('ws_add_methods', 'picasa_wa_add_ws_method'); 
    2427 
     
    6366  } 
    6467} 
     68 
     69function picasa_wa_init() 
     70{ 
     71  global $conf; 
     72  include_once(PICASA_WA_PATH . 'maintain.inc.php'); 
     73  $maintain = new Google2Piwigo_maintain(PICASA_WA_ID); 
     74  $maintain->autoUpdate(PICASA_WA_VERSION, 'install'); 
     75 
     76  $conf['google2piwigo'] = unserialize($conf['google2piwigo']); 
     77} 
Note: See TracChangeset for help on using the changeset viewer.