Exemple #1
0
        $app->render('authorization_page.php');
    }
});
$app->post('/oauth/authorize', function () use($app, $server) {
    $request = OAuth2\Request::createFromGlobals();
    $response = new OAuth2\Response();
    if (!$server->validateAuthorizeRequest($request, $response)) {
        $app->view()->setData(['response' => json_decode($response->getResponseBody())]);
        $app->render('error.php');
    } else {
        $api = new \Aums\API(trim($_POST['username']), trim($_POST['password']));
        try {
            $rollNo = $api->login(false)['roll_no'];
            $server->handleAuthorizeRequest($request, $response, true, $rollNo);
            $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40);
            DB::insert('authorization_codes_map', ['authorization_code' => $code, 'hash' => \Aums\Encryption::encode($_POST['password'], $code)]);
            $app->response->redirect($response->getHttpHeader('Location'));
        } catch (CredentialsInvalidException $e) {
            $app->response->redirect($_SERVER['REQUEST_URI'] . '&auth_error=incorrect');
        }
    }
});
$app->post('/oauth/resource/basic', function () use($server) {
    $request = OAuth2\Request::createFromGlobals();
    $response = new OAuth2\Response();
    $scopeRequired = 'basic';
    if (!$server->verifyResourceRequest($request, $response, $scopeRequired)) {
        $server->getResponse()->send();
        die;
    }
    $api = new \Aums\API('username', 'password');
Exemple #2
0
 /**
  * Download and store the profile image locally.
  *
  * @param string $name                of the student
  * @param string $encodedEnrollmentId of the student
  *
  * @throws AumsOfflineException
  *
  * @return string The image's filename for later reference
  */
 private function storeStudentImage($name, $encodedEnrollmentId)
 {
     $params = ['action' => 'SHOW_STUDENT_PHOTO', 'encodedenrollmentId' => $encodedEnrollmentId, 'flag' => 'photo'];
     $response = $this->client->get('/aums/FileUploadServlet', $params);
     $imageName = Encryption::encode($name . ' ' . time());
     if ($response->getCode() == 200) {
         $handle = fopen($this->storageDir . '/images/' . $imageName, 'w');
         fwrite($handle, $response->getBody());
         fclose($handle);
         return $imageName;
     } else {
         throw new AumsOfflineException('Cannot connect to server: Error ' . $response->getCode());
     }
 }