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

MICROSOFT pear 예제 코드

  1. <?php
  2. /*
  3.  * oops\AUTH2 MICROSOFT test page
  4.  *
  5.  * oops\AUTH2\MICROSOFT 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/MICROSOFT.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. $logout_point sprintf (
  40.     '%s://%s',
  41.     $_SERVER['HTTPS''https' 'http'$_SERVER['HTTP_HOST']
  42. );
  43.  
  44. $appId = (object) array (
  45.     'id'       => 'APPLICATION_ID',           // Application(Client) ID
  46.     'secret'   => 'APPLICATION_SECRET_KEY',   // Client Secret
  47.     'callback' => $callback,                  // Redirection(Callback) URI
  48.     'tenant'   => 'common',                   // 'common', 'organizations', 'cunsumers', TENANT ID
  49.                                               // See also https://docs.microsoft.com/ko-kr/azure/active-directory/develop/active-directory-v2-protocols#endpoints
  50.     'baseurl'  => $logout_point               // URL after logout (must regist as Redirection URI)
  51. );
  52.  
  53. try {
  54.     $oauth2 new oops\OAUTH2\MICROSOFT ($appId);
  55.  
  56.     // logout 시에는 callback url에 logout parameter를 추가하고,
  57.     // logout 후에 redirect가 필요하면 redirect parameter까지 추가한다.
  58.     /*
  59.      * Azure Active directory 는 logout 과정(MICROSOFT::reqLogout method)에서
  60.      * 직접 rediretion 을 해 주기 때문에 이 과정이 필요 없다.
  61.     if ( isset ($_GET['logout']) ) {
  62.         unset ($_SESSION['oauth2']);
  63.  
  64.         if ( $_GET['redirect'] )
  65.             Header ('Location: ' . $redirect);
  66.  
  67.         printf ('%s Complete logout', strtoupper ($appId->vendor));
  68.         exit;
  69.     }
  70.      */
  71.  
  72.     $user $oauth2->Profile ();
  73.     $uid sprintf ('%s:%s'$appId->vendor$user->id);
  74.     // tenant 가 common 일 경우에는 profile image를 제공하지 않고 있다.
  75.     $_SESSION['oauth2'= (object) array (
  76.         'uid' => $uid,
  77.         'name' => $user->name,
  78.         'email' => $user->email,
  79.         'img' => $user->img,
  80.         'logout' => $callback '?logout'
  81.     );
  82.  
  83.     print_r ($_SESS['oauth2']);
  84. catch myException $e {
  85.     echo $e->Message ("\n";
  86.     print_r ($e->TraceAsArray);
  87.     $e->finalize ();
  88. }

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