Exemplo n.º 1
0
 /**
  * 控制器执行主逻辑函数
  */
 public function invoke($uri = null)
 {
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $path = explode('?', $uri);
     $parts = array_slice(explode('/', $path[0]), 2);
     if ($parts[0] === "authorize") {
         $oauth = new PDOOAuth2();
         if ($_POST) {
             $oauth->finishClientAuthorization($_POST["accept"] == "Yep", $_POST);
         }
         $auth_params = $oauth->getAuthorizeParams();
         $inputs = "";
         foreach ($auth_params as $k => $v) {
             $inputs = $inputs . '<input type="hidden" name="' . $k . '" value="' . $v . '" />';
         }
         $content = '<html>' . '<head>Authorize</head>' . '<body>' . '<form method="post" action="http://web.miniyun.cn/miniyun_oauth2/api.php/1/oauth2/authorize">' . $inputs . 'Do you authorize the app to do its thing?' . '<p>' . ' <input type="submit" name="accept" value="Yep" />' . '<input type="submit" name="accept" value="Nope" />' . ' </p>' . '</form>' . '</body>' . ' </html>';
         echo $content;
     } elseif ($parts[0] === "token") {
         $oauth = new PDOOAuth2();
         $token = $oauth->grantAccessToken();
         #添加登陆日志
         $deviceId = $oauth->getVariable("device_id");
         MiniLog::getInstance()->createLogin($deviceId);
         #返回site_id,便于与cloud.miniyun.cn通信
         $token["site_id"] = MiniSiteUtils::getSiteID();
         echo json_encode($token);
     }
 }
Exemplo n.º 2
0
/**
 * @file
 * Sample authorize endpoint.
 *
 * Obviously not production-ready code, just simple and to the point.
 *
 * In reality, you'd probably use a nifty framework to handle most of the crud for you.
 */

require "lib/PDOOAuth2.php";

$oauth = new PDOOAuth2();

if ($_POST) {
  $oauth->finishClientAuthorization($_POST["accept"] == "Yep", $_POST);
}

$auth_params = $oauth->getAuthorizeParams();

?>
<html>
  <head>Authorize</head>
  <body>
    <form method="post" action="authorize.php">
      <?php foreach ($auth_params as $k => $v) { ?>
      <input type="hidden" name="<?php echo $k ?>" value="<?php echo $v ?>" />
      <?php } ?>
      Do you authorize the app to do its thing?
      <p>
        <input type="submit" name="accept" value="Yep" />
Exemplo n.º 3
0
 public function applications()
 {
     JRequest::setVar('view', 'applications');
     $mainframe = JFactory::getApplication();
     $apps = new Applications();
     // this is for auto installation method
     $redirectUri = JRequest::getVar('redirect_uri');
     $clientId = JRequest::getVar('client_id');
     $clientSecret = JRequest::getVar('client_secret');
     $deviceId = JRequest::getVar('deviceId');
     // if this is a request for grant/revoke
     if ($_POST && $deviceId) {
         switch (JRequest::getVar('deviceAction')) {
             case 'grant':
                 $apps->grantAccess($deviceId);
                 break;
             case 'revoke':
                 $apps->revokeAccess($deviceId);
                 break;
         }
     } else {
         if ($clientId && $clientSecret && $redirectUri) {
             header("Content-Type: application/json");
             header("Cache-Control: no-store");
             JRequest::setVar('installing', true);
             if ($_POST || JRequest::getVar('silent')) {
                 $model = OauthFactory::getModel('Application');
                 // use library for the OAuth to standardize
                 require_once JPATH_ROOT . DS . 'components' . DS . 'com_oauth' . DS . 'libraries' . DS . 'PDOOAuth2.inc';
                 $oauth = new PDOOAuth2();
                 if ($oauth->addClient($clientId, $clientSecret, $redirectUri)) {
                     $authData = array('client_id' => $clientId, 'response_type' => 'code', 'redirect_uri' => $redirectUri);
                     $oauth->finishClientAuthorization(true, $authData);
                     /* if this is a silent request, give a silent feedback */
                     if (JRequest::getVar('silent')) {
                         echo json_encode(array('success' => 'true'));
                         exit;
                     }
                     JRequest::setVar('authorize', true);
                     JRequest::setVar('appName', $clientId);
                     $mainframe->enqueueMessage(JText::_('COM_OAUTH_LABEL_APPLICATION_INSTALL'));
                 } else {
                     if (JRequest::getVar('silent')) {
                         echo json_encode(array('success' => false, 'error' => JText::_('COM_OAUTH_LABEL_FAILED_TO_REGISTER')));
                         exit;
                     }
                     $mainframe->enqueueMessage(JText::_('COM_OAUTH_LABEL_FAILED_TO_REGISTER'), 'Error');
                 }
             }
         }
     }
     parent::display();
 }