[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/wepay/demoapp/ -> login.php (source)

   1  <?php
   2  require  './_shared.php';
   3  
   4  // ** YOU MUST CHANGE THIS FOR THE SAMPLE APP TO WORK **
   5  $redirect_uri = 'http://YOUR SERVER NAME/login.php';
   6  $scope = WePay::getAllScopes();
   7  
   8  // If we are already logged in, send the user home
   9  if (!empty($_SESSION['wepay_access_token'])) {
  10      header('Location: index.php');
  11      exit;
  12  }
  13  
  14  // If the authentication dance returned an error, catch it to avoid a
  15  // redirect loop. This usually indicates some sort of application issue,
  16  // like a domain mismatch on your redirect_uri
  17  if (!empty($_GET['error'])) {
  18      echo 'Error during user authentication: ';
  19      echo htmlentities($_GET['error_description']);
  20      exit;
  21  }
  22  
  23  // If we don't have a code from being redirected back here,
  24  // send the user to WePay to grant permissions.
  25  if (empty($_GET['code'])) {
  26      $uri = WePay::getAuthorizationUri($scope, $redirect_uri);
  27      header("Location: $uri");
  28  }
  29  else {
  30      $info = WePay::getToken($_GET['code'], $redirect_uri);
  31      if ($info) {
  32          // Normally you'd integrate this into your existing auth system
  33          $_SESSION['wepay_access_token'] = $info->access_token;
  34          // If desired, you can also store $info->user_id somewhere
  35          header('Location: index.php');
  36      }
  37      else {
  38          // Unable to obtain access token
  39          echo 'Unable to obtain access token from WePay.';
  40      }
  41  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1