Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $om = $this->getContainer()->get('claroline.persistence.object_manager');
     $host = $input->getArgument('host');
     $master = $input->getArgument('master');
     $name = $input->getArgument('name');
     $request = new FriendRequest();
     $request->setHost($host);
     $request->setName($name);
     $om->persist($request);
     $om->flush();
     $this->getContainer()->get('claroline.manager.oauth_manager')->createFriendRequest($request, $master);
     $output->writeln('Platform added !');
 }
Example #2
0
 private function adminQuery(FriendRequest $request, $url, $payload = null, $type = 'GET')
 {
     $access = $request->getClarolineAccess();
     if ($access === null) {
         throw new \Exception('The oauth tokens were lost. Please ask for a new authentication.');
     }
     $firstTry = $request->getHost() . '/' . $url . '?access_token=' . $access->getAccessToken();
     $serverOutput = $this->curlManager->exec($firstTry, $payload, $type);
     $json = json_decode($serverOutput, true);
     if ($json) {
         if (array_key_exists('error', $json)) {
             if ($json['error'] === 'access_denied' || $json['error'] === 'invalid_grant') {
                 $access = $this->oauthManager->connect($request->getHost(), $access->getRandomId(), $access->getSecret(), $access->getFriendRequest());
                 $secondTry = $request->getHost() . '/' . $url . '?access_token=' . $access->getAccessToken();
                 $serverOutput = $this->curlManager->exec($secondTry, $payload, $type);
             }
         }
     }
     return $serverOutput;
 }
Example #3
0
 /**
  * Only 1 access per client !
  */
 private function createAccess($randomId, $secret, $token, FriendRequest $request)
 {
     //1st step, remove any existing access
     $access = $this->om->getRepository('Claroline\\CoreBundle\\Entity\\Oauth\\ClarolineAccess')->findOneByRandomId($randomId);
     if ($access === null) {
         $access = new ClarolineAccess();
     }
     $access->setRandomId($randomId);
     $access->setSecret($secret);
     $access->setAccessToken($token);
     $request->setIsActivated(true);
     $access->setFriendRequest($request);
     $this->om->persist($request);
     $this->om->persist($access);
     $this->om->flush();
     return $access;
 }
Example #4
0
 /**
  * @EXT\Route(
  *     "/request/friend/remove/{friend}",
  *     name="oauth_request_friend_remove",
  *     options = {"expose"=true}
  * )
  * @SEC\PreAuthorize("canOpenAdminTool('platform_parameters')")
  *
  * @return Response
  */
 public function removeFriendRequest(FriendRequest $friend)
 {
     $oldid = $friend->getId();
     $this->oauthManager->removeFriendRequest($friend);
     return new JsonResponse(array('id' => $oldid));
 }