示例#1
0
     }
 });
 // Request logging
 $app->container->singleton('requestLog', function () use($app) {
     $logService = new LogService($app);
     $logDocument = $logService->logRequest($app->request);
     return $logDocument;
 });
 // Auth - token
 $app->container->singleton('auth', function () use($app) {
     if (!$app->request->isOptions() && !($app->request->getPathInfo() === '/about')) {
         $basicAuthService = new BasicAuthService($app);
         $oAuthService = new OAuthService($app);
         $token = null;
         try {
             $token = $oAuthService->extractToken($app->request);
             $app->requestLog->addRelation('oAuthToken', $token)->save();
         } catch (AuthFailureException $e) {
             // Ignore
         }
         try {
             $token = $basicAuthService->extractToken($app->request);
             $app->requestLog->addRelation('basicToken', $token)->save();
         } catch (AuthFailureException $e) {
             // Ignore
         }
         if (null === $token) {
             throw new \Exception('Credentials invalid!', Resource::STATUS_UNAUTHORIZED);
         }
         return $token;
     }