Ignore:
Timestamp:
Jun 29, 2014, 4:09:08 PM (10 years ago)
Author:
mistic100
Message:

fix oauth flow

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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');
Note: See TracChangeset for help on using the changeset viewer.