/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { if ($this->cached) { return $this->cached; } $url = Url::createFromUrl(''); $url->setHost(null); $url->setScheme(null); if (\Config::get('concrete.seo.canonical_url')) { $canonical = UrlImmutable::createFromUrl(Config::get('concrete.seo.canonical_url')); // If the request is over https and the canonical url is http, lets just say https for the canonical url. if (strtolower($canonical->getScheme()) == 'http' && strtolower($this->request->getScheme()) == 'https') { $url->setScheme('https'); } else { $url->setScheme($canonical->getScheme()); } $url->setHost($canonical->getHost()); if (intval($canonical->getPort()->get()) > 0) { $url->setPort($canonical->getPort()); } } else { $host = $this->request->getHost(); $scheme = $this->request->getScheme(); if ($scheme && $host) { $url->setScheme($scheme)->setHost($host)->setPortIfNecessary(Request::getInstance()->getPort()); } } if ($relative_path = \Core::getApplicationRelativePath()) { $url = $url->setPath($relative_path); } $this->cached = UrlImmutable::createFromUrl($url); return $this->cached; }
/** * Create a service object given a ServiceFactory object * * @param \OAuth\ServiceFactory $factory * @return \OAuth\Common\Service\ServiceInterface */ public function createService(ServiceFactory $factory) { $appId = $this->config->get('auth.community.appid'); $appSecret = $this->config->get('auth.community.secret'); // Get the callback url /** @var Url $callbackUrl */ $callbackUrl = $this->urlResolver->resolve(['/ccm/system/authentication/oauth2/community/callback/']); if ($callbackUrl->getHost() == '') { $callbackUrl = $callbackUrl->setHost($this->request->getHost()); $callbackUrl = $callbackUrl->setScheme($this->request->getScheme()); } // Create a credential object with our ID, Secret, and callback url $credentials = new Credentials($appId, $appSecret, (string) $callbackUrl); // Create a new session storage object and pass it the active session $storage = new SymfonySession($this->session, false); // Create the service using the oauth service factory return $factory->createService('community', $credentials, $storage); }
/** * Create a service object given a ServiceFactory object * * @return \OAuth\Common\Service\ServiceInterface */ public function createService() { $appId = $this->config->get('auth.twitter.appid'); $appSecret = $this->config->get('auth.twitter.secret'); $verifyPeer = $this->config->get('app.curl.verifyPeer'); /** @var ServiceFactory $factory */ $factory = $this->app->make('oauth/factory/service', array(CURLOPT_SSL_VERIFYPEER => $verifyPeer)); // Get the callback url $callbackUrl = $this->urlResolver->resolve(['/ccm/system/authentication/oauth2/twitter/callback/']); if ($callbackUrl->getHost() == '') { $callbackUrl = $callbackUrl->setHost($this->request->getHost()); $callbackUrl = $callbackUrl->setScheme($this->request->getScheme()); } // Create a credential object with our ID, Secret, and callback url $credentials = new Credentials($appId, $appSecret, (string) $callbackUrl); // Create a new session storage object and pass it the active session $storage = new SymfonySession($this->session, false); // Create the service using the oauth service factory return $factory->createService('twitter', $credentials, $storage); }
/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { if ($this->cached) { return $this->cached; } $config = $this->app['config']; // Determine trailing slash setting $trailing_slashes = $config->get('concrete.seo.trailing_slash') ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED; $url = Url::createFromUrl('', $trailing_slashes); $url->setHost(null); $url->setScheme(null); if ($config->get('concrete.seo.canonical_url')) { $canonical = UrlImmutable::createFromUrl($config->get('concrete.seo.canonical_url'), $trailing_slashes); // If the request is over https and the canonical url is http, lets just say https for the canonical url. if (strtolower($canonical->getScheme()) == 'http' && strtolower($this->request->getScheme()) == 'https') { $url->setScheme('https'); } else { $url->setScheme($canonical->getScheme()); } $url->setHost($canonical->getHost()); if (intval($canonical->getPort()->get()) > 0) { $url->setPort($canonical->getPort()); } } else { $host = $this->request->getHost(); $scheme = $this->request->getScheme(); if ($scheme && $host) { $url->setScheme($scheme)->setHost($host)->setPort($this->request->getPort()); } } if ($relative_path = $this->app['app_relative_path']) { $url = $url->setPath($relative_path); } $this->cached = UrlImmutable::createFromUrl($url, $trailing_slashes); return $this->cached; }
/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * If the first argument provided is a page object, we will use that object to determine the site tree * (and thus the canonical url) to use. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { $config = null; $page = null; // Canonical urls for pages can be different than for the entire site if (count($arguments) && head($arguments) instanceof Page) { /** @var Page $page */ $page = head($arguments); $tree = $page->getSiteTreeObject(); if ($tree instanceof SiteTree && ($site = $tree->getSite())) { $config = $site->getConfigRepository(); } } elseif ($this->cached) { return $this->cached; } // Get the config from the current site tree if ($config === null && $this->app->isInstalled()) { $site = $this->app['site']->getSite(); if (is_object($site)) { $config = $site->getConfigRepository(); } } // Determine trailing slash setting $trailing_slashes = $config && $config->get('seo.trailing_slash') ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED; $url = UrlImmutable::createFromUrl('', $trailing_slashes); $url = $url->setHost(null); $url = $url->setScheme(null); if ($config && ($configUrl = $site->getSiteCanonicalURL())) { $canonical = UrlImmutable::createFromUrl($configUrl, $trailing_slashes); if ($configSslUrl = $config->get('seo.canonical_ssl_url')) { $canonical_ssl = UrlImmutable::createFromUrl($configSslUrl, $trailing_slashes); } $url = $url->setHost($canonical->getHost()); $url = $url->setScheme($canonical->getScheme()); // If the request is over https if (strtolower($this->request->getScheme()) == 'https') { // If the canonical ssl url is set, respect the canonical ssl url. if (isset($canonical_ssl)) { $url = $url->setHost($canonical_ssl->getHost()); $url = $url->setScheme($canonical_ssl->getScheme()); if (intval($canonical_ssl->getPort()->get()) > 0) { $url = $url->setPort($canonical_ssl->getPort()); } } else { // If the canonical url is http, lets just say https for the canonical url. if (strtolower($canonical->getScheme()) == 'http') { $url = $url->setScheme('https'); } if (intval($canonical->getPort()->get()) > 0) { $url = $url->setPort($canonical->getPort()); } } } elseif (intval($canonical->getPort()->get()) > 0) { $url = $url->setPort($canonical->getPort()); } } else { // This fallthrough is dangerous. Make sure that you define your canonical URL so that we don't have to guess! $host = $this->request->getHost(); $scheme = $this->request->getScheme(); if ($scheme && $host) { $url = $url->setScheme($scheme)->setHost($host)->setPort($this->request->getPort()); } } if ($relative_path = $this->app['app_relative_path']) { $url = $url->setPath($relative_path); } // Don't cache page specific canonical urls if (!$page) { $this->cached = $url; } return $url; }
/** * Returns the host name. * * This method can read the client port from the "X-Forwarded-Host" header * when trusted proxies were set via "setTrustedProxies()". * * The "X-Forwarded-Host" header must contain the client host name. * * If your reverse proxy uses a different header name than "X-Forwarded-Host", * configure it via "setTrustedHeaderName()" with the "client-host" key. * * @return string * * @throws \UnexpectedValueException when the host name is invalid * * @api */ public function getHost() { return parent::getHost(); }