oops-OAUTH2
[ class tree: oops-OAUTH2 ] [ index: oops-OAUTH2 ] [ all elements ]

GITHUB pear 예제 코드

  1. <?php
  2. /*
  3.  * oops\AUTH2 GITHUB test page
  4.  *
  5.  * oops\AUTH2\GITHUB package는 독립적으로도 사용이 가능하다.
  6.  *
  7.  * dependency
  8.  *
  9.  * pear oops/myException
  10.  * pear oops/HTTPRelay
  11.  */
  12.  
  13.  
  14. $devel false;
  15. if $devel == true {
  16.     $iniget function_exists ('___ini_get''___ini_get' 'ini_get';
  17.     $iniset function_exists ('___ini_set''___ini_set' 'ini_set';
  18.  
  19.     $cwd getcwd ();
  20.     $ccwd basename ($cwd);
  21.     if $ccwd == 'tests' {
  22.         $oldpath $iniget ('include_path');
  23.         $newpath preg_replace ("!/{$ccwd}!"''$cwd);
  24.         $iniset ('include_path'$newpath ':' $oldpath);
  25.     }
  26. }
  27.  
  28. require_once 'OAUTH2/GITHUB.php';
  29.  
  30. set_error_handler ('myException::myErrorHandler');
  31.  
  32. $callback sprintf (
  33.     '%s://%s%s',
  34.     $_SERVER['HTTPS''https' 'http',
  35.     $_SERVER['HTTP_HOST'],
  36.     $_SERVER['REQUEST_URI']
  37. );
  38.  
  39. $appId = (object) array (
  40.     'id'       => 'APPLICATION_ID',
  41.     'secret'   => 'APPLICATION_SECRET_KEY',
  42.     'callback' => $callback,
  43. );
  44.  
  45. try {
  46.     $oauth2 new oops\OAUTH2\GITHUB ($appId);
  47.  
  48.     // logout 시에는 callback url에 logout parameter를 추가하고,
  49.     // logout 후에 redirect가 필요하면 redirect parameter까지 추가한다.
  50.     if isset ($_GET['logout']) ) {
  51.         unset ($_SESSION['oauth2']);
  52.  
  53.         if $_GET['redirect')
  54.             Header ('Location: ' $redirect);
  55.  
  56.         printf ('%s Complete logout'strtoupper ($appId->vendor));
  57.         exit;
  58.     }
  59.  
  60.     $user $oauth2->Profile ();
  61.     $uid sprintf ('%s:%s'$appId->vendor$user->id);
  62.     $_SESSION['oauth2'= (object) array (
  63.         'uid' => $uid,
  64.         'name' => $user->name,
  65.         'email' => $user->email,
  66.         'img' => $user->img,
  67.         'logout' => $callback '?logout'
  68.     );
  69.  
  70.     print_r ($_SESS['oauth2']);
  71. catch myException $e {
  72.     echo $e->Message ("\n";
  73.     print_r ($e->TraceAsArray);
  74.     $e->finalize ();
  75. }

Documentation generated on Tue, 14 May 2019 02:00:03 +0900 by phpDocumentor 1.4.4