Redirects the client for authorization.

@param  array $options
@param  callable|null $redirectHandler
@return mixed
3095
public function authorize(
        array $options = [],
        callable $redirectHandler = null
    ) {
        $url = $this->getAuthorizationUrl($options);
        if ($redirectHandler) {
            return $redirectHandler($url, $this);
        }

        // @codeCoverageIgnoreStart
        header('Location: ' . $url);
        exit;
        // @codeCoverageIgnoreEnd
    }
72728
protected function implicitAskResourceOwnerForApproval(
        array $parameters,
        ClientInterface $client,
        string $redirectUri = null,
        int $maxStateLength = null
    ): ResponseInterface {
        $state = $this->implicitGetState($parameters);
        if ($maxStateLength !== null && strlen($state) > $maxStateLength) {
            throw new OAuthTokenRedirectException(
                OAuthTokenRedirectException::ERROR_INVALID_REQUEST,
                $redirectUri,
                $state
            );
        }

        if ($client->isImplicitGrantEnabled() === false) {
            throw new OAuthTokenRedirectException(
                OAuthTokenRedirectException::ERROR_UNAUTHORIZED_CLIENT,
                $redirectUri,
                $state
            );
        }

        $scope = $this->implicitGetScope($parameters);
        list ($isScopeValid, $scopeList, $isScopeModified) =
            $this->implicitGetIntegration()->implicitValidateScope($client, $scope);
        if ($isScopeValid === false) {
            throw new OAuthTokenRedirectException(
                OAuthTokenRedirectException::ERROR_INVALID_SCOPE,
                $redirectUri,
                $state
            );
        }

        $response = $this->implicitGetIntegration()->implicitCreateAskResourceOwnerForApprovalResponse(
            $client,
            $redirectUri,
            $isScopeModified,
            $scopeList,
            $state,
            $parameters
        );

        return $response;
    }
1333416
static function loadProvider($key, $redirect) {
    if (!$redirect) {
      throw new \InvalidArgumentException("No redirect provided.");
    }

    switch ($key) {
      case "google":
        return new GoogleWithOpenID(array(
          'clientId' =>\Openclerk\Config::get("oauth2_google_client_id"),
          'clientSecret' => \Openclerk\Config::get("oauth2_google_client_secret"),
          'redirectUri' => $redirect,
          'scopes' => array('email', 'openid'),
          'openid.realm' => \Openclerk\Config::get('openid_host'),
        ));

      case "facebook":
        return new \League\OAuth2\Client\Provider\Facebook(array(
          'clientId' =>\Openclerk\Config::get("oauth2_facebook_app_id"),
          'clientSecret' => \Openclerk\Config::get("oauth2_facebook_app_secret"),
          'redirectUri' => $redirect,
          'scopes' => array('email'),
        ));

      case "github":
        return new \League\OAuth2\Client\Provider\Github(array(
          'clientId' =>\Openclerk\Config::get("oauth2_github_client_id"),
          'clientSecret' => \Openclerk\Config::get("oauth2_github_client_secret"),
          'redirectUri' => $redirect,
          'scopes' => array('email'),
        ));

      default:
        throw new UserAuthenticationException("No such known OAuth2 provider '$key'");
    }
  }
1126850
public function delete($handle, array $options = [])
    {
        /** @var AbstractHttpRequest $request */
        $request          = $this->getRequest();
        $request->options = $options;
        $request->path    = $this->client->fullDatabasePath . static::API_PATH . '/' . $handle;
        $request->method  = static::METHOD_DELETE;

        return $this->getReturnObject($request);
    }
1277807
public function getRedirect(): ?Redirector
    {
        if (!$this->hasRedirect()) {
            $this->setRedirect($this->getDefaultRedirect());
        }
        return $this->redirect;
    }
239347
public function request($url, $options)
    {
        $this->url = $url;
        $this->options = array_replace_recursive($this->settings['defaults'], $options);

        try {
            return $this->handleRequest();
        } catch (TokenExpiredException $e) {
            $this->refresh();

            return $this->handleRequest();
        }
    }
520712
public function send(RequestInterface $request, array $options = [])
    {
        $response = parent::send($request, $options);

        // re-authenticate if 403 and token is expired
        if (
            $this->token &&
            $response->getStatusCode() === 403 &&
            $this->isTokenExpired($this->token) &&
            !$this->authenticate()
        ) {
            throw new ClientException('Cannot re-authenticate.');
        }

        $this->checkResponse($response);

        return $response;
    }
836523
public function process(HTTPRequest $request, callable $delegate)
    {
        // Handle any redirects
        $redirect = $this->getRedirect($request);
        if ($redirect) {
            return $redirect;
        }

        /** @var HTTPResponse $response */
        $response = $delegate($request);
        if ($this->hasBasicAuthPrompt($response)
            && $request->getScheme() !== 'https'
            && $this->getForceBasicAuthToSSL()
        ) {
            return $this->redirectToScheme($request, 'https');
        }

        return $response;
    }
696806
public function redirect($url = null, $exitAfter = true)
    {
        if (empty($url)) {
            $authRequest = $this->_stateMgr->get('authRequest');
            /* @var AuthRequest $authRequest */
            if ($authRequest) {
                $url = $authRequest->getReturnUrl();
                $this->_stateMgr->set('authRequest');
            }
        }
        parent::redirect($url, $exitAfter);
    }
579292
public function handleRedirect(RedirectEvent $event)
    {
        /** @var Controller $controllerAdapter */
        $controllerAdapter = $this->framework->getAdapter(Controller::class);

        $controllerAdapter->redirect($event->getNewLocation(), $event->getStatusCode());
    }
1106493
def options(self, url, callback=None, retry=0, **kwargs):
        """"""
        kwargs.setdefault("allow_redirects", True)
        return self.request(
            "options", url=url, callback=callback, retry=retry, **kwargs
        )
437434
protected function request($url, $options = array()) {
        // Reset here so that the data is valid when result returned from cache, or if we return due to a blacklist hit.
        $this->reset_request_state_vars();

        if ((defined('PHPUNIT_TEST') && PHPUNIT_TEST)) {
            if ($mockresponse = array_pop(self::$mockresponses)) {
                $this->info = [ 'http_code' => 200 ];
                return $mockresponse;
            }
        }

        // If curl security is enabled, check the URL against the blacklist before calling curl_exec.
        // Note: This will only check the base url. In the case of redirects, the blacklist is also after the curl_exec.
        if (!$this->ignoresecurity && $this->securityhelper->url_is_blocked($url)) {
            $this->error = $this->securityhelper->get_blocked_url_string();
            return $this->error;
        }

        // Set the URL as a curl option.
        $this->setopt(array('CURLOPT_URL' => $url));

        // Create curl instance.
        $curl = curl_init();

        $this->apply_opt($curl, $options);
        if ($this->cache && $ret = $this->cache->get($this->options)) {
            return $ret;
        }

        $ret = curl_exec($curl);
        $this->info  = curl_getinfo($curl);
        $this->error = curl_error($curl);
        $this->errno = curl_errno($curl);
        // Note: $this->response and $this->rawresponse are filled by $hits->formatHeader callback.

        // In the case of redirects (which curl blindly follows), check the post-redirect URL against the blacklist entries too.
        if (intval($this->info['redirect_count']) > 0 && !$this->ignoresecurity
            && $this->securityhelper->url_is_blocked($this->info['url'])) {
            $this->reset_request_state_vars();
            $this->error = $this->securityhelper->get_blocked_url_string();
            curl_close($curl);
            return $this->error;
        }

        if ($this->emulateredirects and $this->options['CURLOPT_FOLLOWLOCATION'] and $this->info['http_code'] != 200) {
            $redirects = 0;

            while($redirects <= $this->options['CURLOPT_MAXREDIRS']) {

                if ($this->info['http_code'] == 301) {
                    // Moved Permanently - repeat the same request on new URL.

                } else if ($this->info['http_code'] == 302) {
                    // Found - the standard redirect - repeat the same request on new URL.

                } else if ($this->info['http_code'] == 303) {
                    // 303 See Other - repeat only if GET, do not bother with POSTs.
                    if (empty($this->options['CURLOPT_HTTPGET'])) {
                        break;
                    }

                } else if ($this->info['http_code'] == 307) {
                    // Temporary Redirect - must repeat using the same request type.

                } else if ($this->info['http_code'] == 308) {
                    // Permanent Redirect - must repeat using the same request type.

                } else {
                    // Some other http code means do not retry!
                    break;
                }

                $redirects++;

                $redirecturl = null;
                if (isset($this->info['redirect_url'])) {
                    if (preg_match('|^https?://|i', $this->info['redirect_url'])) {
                        $redirecturl = $this->info['redirect_url'];
                    }
                }
                if (!$redirecturl) {
                    foreach ($this->response as $k => $v) {
                        if (strtolower($k) === 'location') {
                            $redirecturl = $v;
                            break;
                        }
                    }
                    if (preg_match('|^https?://|i', $redirecturl)) {
                        // Great, this is the correct location format!

                    } else if ($redirecturl) {
                        $current = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
                        if (strpos($redirecturl, '/') === 0) {
                            // Relative to server root - just guess.
                            $pos = strpos('/', $current, 8);
                            if ($pos === false) {
                                $redirecturl = $current.$redirecturl;
                            } else {
                                $redirecturl = substr($current, 0, $pos).$redirecturl;
                            }
                        } else {
                            // Relative to current script.
                            $redirecturl = dirname($current).'/'.$redirecturl;
                        }
                    }
                }

                curl_setopt($curl, CURLOPT_URL, $redirecturl);
                $ret = curl_exec($curl);

                $this->info  = curl_getinfo($curl);
                $this->error = curl_error($curl);
                $this->errno = curl_errno($curl);

                $this->info['redirect_count'] = $redirects;

                if ($this->info['http_code'] === 200) {
                    // Finally this is what we wanted.
                    break;
                }
                if ($this->errno != CURLE_OK) {
                    // Something wrong is going on.
                    break;
                }
            }
            if ($redirects > $this->options['CURLOPT_MAXREDIRS']) {
                $this->errno = CURLE_TOO_MANY_REDIRECTS;
                $this->error = 'Maximum ('.$this->options['CURLOPT_MAXREDIRS'].') redirects followed';
            }
        }

        if ($this->cache) {
            $this->cache->set($this->options, $ret);
        }

        if ($this->debug) {
            echo '<h1>Return Data</h1>';
            var_dump($ret);
            echo '<h1>Info</h1>';
            var_dump($this->info);
            echo '<h1>Error</h1>';
            var_dump($this->error);
        }

        curl_close($curl);

        if (empty($this->error)) {
            return $ret;
        } else {
            return $this->error;
            // exception is not ajax friendly
            //throw new moodle_exception($this->error, 'curl');
        }
    }
52659
public function redirectIfNotUrl($url, array $allowParams = array())
    {
        if ($url != $this->getRequest()->getRequestUri()) {
            $redirect = true;
            $newArgs = array();
            try {
                $tmp = parse_url($this->getRequest()->getRequestUri());
                if (isset($tmp['path']) && $tmp['path'] == $url) {
                    $redirect = false;
                }
                if (isset($tmp['query'])) {
                    parse_str($tmp['query'], $args);
                    $alloweds = array_merge($allowParams, $this->getParameter('nyroDev_utility.redirectIfNotUrl_params', array()));
                    foreach ($alloweds as $k) {
                        if (isset($args[$k])) {
                            $newArgs[$k] = $args[$k];
                        }
                    }
                    $redirect = count($newArgs) != count($args);
                }
            } catch (\Exception $e) {
                $redirect = false;
            }
            if ($redirect) {
                return new RedirectResponse($url.(count($newArgs) ? '?'.http_build_query($newArgs) : ''), 301);
            }
        }

        return false;
    }
218220
public function redirect($redirectUrl = null)
    {
        $state = null;

        if (!is_null($redirectUrl)) {
            $this->redirectUrl = $redirectUrl;
        }

        if ($this->usesState()) {
            $state = $this->makeState();
        }

        return new RedirectResponse($this->getAuthUrl($state));
    }
146326
protected function selectValidRedirectUri(ClientInterface $client, string $redirectUri = null): ?string
    {
        $validUri = null;
        $uris     = $client->getRedirectUriStrings();
        if (empty($redirectUri) === true) {
            // if no redirect provided and it's optional we require client to have
            // exactly 1 redirect URI so we know where to redirect.
            if (($this->isInputUriOptional() === true && count($uris) === 1)) {
                $validUri = $uris[0];
            }

            return $validUri;
        }

        // check client has provided redirect URI
        if (in_array($redirectUri, $client->getRedirectUriStrings()) === true) {
            $validUri = $redirectUri;
        }

        return $validUri;
    }
730467
public function redirect()
    {
        $this->request->session()->put(
            'oauth.temp', $temp = $this->server->getTemporaryCredentials()
        );

        return new RedirectResponse($this->server->getAuthorizationUrl($temp));
    }
1216239
public function redirectByUrl($defaultRedirect = null, $key = null) {
		$redirectUrl = $this->getRedirectUrl($defaultRedirect, $key);

		return $this->_controller->redirect($redirectUrl);
	}