Example #1
0
 public function __construct(HttpUrl $claimedId, HttpClient $httpClient)
 {
     $this->claimedId = $claimedId->makeComparable();
     if (!$claimedId->isValid()) {
         throw new OpenIdException('invalid claimed id');
     }
     $this->httpClient = $httpClient;
     $response = $httpClient->send(HttpRequest::create()->setHeaderVar('Accept', self::HEADER_ACCEPT)->setMethod(HttpMethod::get())->setUrl($claimedId));
     if ($response->getStatus()->getId() != 200) {
         throw new OpenIdException('can\'t fetch document');
     }
     $contentType = $response->getHeader('content-type');
     if (mb_stripos($contentType, self::HEADER_CONT_TYPE) !== false) {
         $this->parseXRDS($response->getBody());
     } elseif ($response->hasHeader(self::HEADER_XRDS_LOCATION)) {
         $this->loadXRDS($response->getHeader(self::HEADER_XRDS_LOCATION));
     } else {
         $this->parseHTML($response->getBody());
     }
     if (!$this->server || !$this->server->isValid()) {
         throw new OpenIdException('bad server');
     } else {
         $this->server->makeComparable();
     }
     if (!$this->realId) {
         $this->realId = $claimedId;
     } elseif (!$this->realId->isValid()) {
         throw new OpenIdException('bad delegate');
     } else {
         $this->realId->makeComparable();
     }
 }
Example #2
0
 private function makeCheckIdRequest(OpenIdCredentials $credentials, HttpUrl $returnTo, $trustRoot = null, $association = null)
 {
     Assert::isTrue($returnTo->isValid());
     $view = RedirectView::create($credentials->getServer()->toString());
     $model = Model::create()->set('openid.ns', self::NAMESPACE_2_0)->set('openid.identity', $credentials->getRealId()->toString())->set('openid.return_to', $returnTo->toString())->set('openid.claimed_id', $credentials->getRealId()->toString());
     foreach ($this->extensions as $extension) {
         $extension->addParamsToModel($model);
     }
     if ($association) {
         Assert::isTrue($association instanceof OpenIdConsumerAssociation && $association->getServer()->toString() == $credentials->getServer()->toString());
         $model->set('openid.assoc_handle', $association->getHandle());
     }
     if ($trustRoot) {
         Assert::isTrue($trustRoot instanceof HttpUrl && $trustRoot->isValid());
         $model->set('openid.trust_root', $trustRoot->toString())->set('openid.realm', $trustRoot->toString());
     }
     return ModelAndView::create()->setModel($model)->setView($view);
 }