Build the authorization code request URL
@return bool
552288
public function authorizationCodeUrl()
    {
        // Get the Discovery URI
        if (!$this->endpointDiscovery()) return false;

        $url = $this->authorization_endpoint;
        $url .= '?response_type=code';
        $url .= '&client_id=' . $this->mpClientId;
        $url .= '&scope=' . $this->scope . ' openid';
        $url .= '&redirect_uri=' . $this->mpRedirectURL;

        return $url;
    }
1112262
public function authenticate() {
		// user denied error
		if (isset($_GET['error']) && $_GET['error'] == 'access_denied') {
			$this->cancel();
			return false;
		}

		// Get the access_token and save them to the session.
		if (isset($_GET['code'])) {
			$code = $_GET['code'];
			$token = $this->getAccessToken($code);
			if (isset($token)) {
				$this->saveAccessToken($token);
				$this->authenticated = true;
			}
		}
		// Redirect to the authorization page
		else {
			if (!$this->restoreAccessToken()) {
				// Use the URL of the current page as the callback URL.
				if (isset($_GET['redirect_uri'])) {
					$redirect_uri = $_GET['redirect_uri'];
				}
				else {
					$server = Yii::app()->request->getHostInfo();
					$path = Yii::app()->request->getUrl();
					$redirect_uri = $server . $path;
				}

				$url = $this->getCodeUrl($redirect_uri, isset($_GET['state']) ? $_GET['state'] : '');
				Yii::app()->request->redirect($url);
			}
		}

		return $this->getIsAuthenticated();
	}
580687
public function requestAccessToken()
    {
        try {
            $this->session->requestAccessToken($_GET['code']);
            return $this;
        } catch (Exception $e) {
            $this->redirectToSpotifyAuthorizeUrl();
        }
    }
1050513
private function authorise()
	{
		$url = $this->getOption('authoriseURL') . '?oauth_token=' . $this->token['key'];

		if ($this->getOption('scope'))
		{
			$scope = \is_array($this->getOption('scope')) ? implode(' ', $this->getOption('scope')) : $this->getOption('scope');
			$url .= '&scope=' . urlencode($scope);
		}

		if ($this->getOption('sendheaders'))
		{
			$this->application->redirect($url);
		}
	}
1310805
public function createAuthCode()
	{
		$authParams = Authorizer::getAuthCodeRequestParams();
		$formParams = array_except($authParams,'client');
		$formParams['client_id'] = $authParams['client']->getId();

		$scope_collection = new \Illuminate\Database\Eloquent\Collection();
		foreach($authParams['scopes'] as $scope)
		{
			$scope_collection->add(Scope::findOrFail($scope->getId()));
		}
		return view('oauth.authorization-form')
			->with('params', $formParams)
			->with('client', $authParams['client'])
			->with('scopes', $scope_collection);
	}
1178058
public function createAuthUrl()
    {
        $this->validConfig();
        $query_string = filter_var_array((array) $this->config, array(
            'client_id' => FILTER_SANITIZE_STRING,
            'scope' => FILTER_SANITIZE_STRING,
            'redirect_uri' => FILTER_SANITIZE_STRING,
            'response_type' => FILTER_SANITIZE_STRING,
        ));
        $auth_url = filter_var($this->config->auth_url, FILTER_SANITIZE_STRING);

        return $auth_url.'/?'.\http_build_query(array(
            'client_id' => $query_string['client_id'],
            'scope' => $query_string['scope'],
            'redirect_uri' => $query_string['redirect_uri'],
            'response_type' => $query_string['response_type'],
        ));
    }
1219613
public function getAuthorizationInfo($authorization_code)
    {
        empty($this->component_access_token) && $this->getComponentAccessToken();
        if (empty($this->component_access_token)) {
            return false;
        }
        $data = array();
        $data['component_appid'] = $this->component_appid;
        $data['authorization_code'] = $authorization_code;
        $url = self::URL_PREFIX . self::QUERY_AUTH_URL . "?component_access_token={$this->component_access_token}";
        $result = Tools::httpPost($url, Tools::json_encode($data));
        $authorization_info = $this->_decode($result, 'authorization_info');
        if (empty($authorization_info)) {
            Tools::log("Get getAuthorizationInfo Faild. {$this->errMsg} [$this->errCode]", "ERR - {$this->authorizer_appid}");
            return false;
        }
        $authorization_info['func_info'] = $this->_parseFuncInfo($authorization_info['func_info']);
        return $authorization_info;
    }
1245832
public function getAuthoriseUrl()
    {
        $clientId = $this->_scopeConfig->getValue(
            \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID
        );

        //callback uri if not set custom
        $redirectUri = $this->helper->getRedirectUri();
        $redirectUri .= 'connector/email/callback';

        $adminUser = $this->auth->getUser();

        //query params
        $params = [
            'redirect_uri' => $redirectUri,
            'scope' => 'Account',
            'state' => $adminUser->getId(),
            'response_type' => 'code',
        ];

        $authorizeBaseUrl = $this->configHelper
            ->getAuthorizeLink();
        $url = $authorizeBaseUrl . http_build_query($params)
            . '&client_id=' . $clientId;

        return $url;
    }
747392
protected function buildAuthorityStr()
    {
        if ($this->host != null) {
            $authority = '//';
            if ($this->userInfo != null) {
                $authority .= $this->userInfo . '@';
            }
            $flag = (strpos($this->host, ':') !== false) && !(substr($this->host, 0,
                        1) == '[') && !(substr($this->host, -1) == ']');
            if ($flag) {
                $authority .= '[';
            }
            $authority .= $this->host;
            if ($flag) {
                $authority .= ']';
            }
            if ($this->port != null) {
                $authority .= ':' . $this->port;
            }
            return $authority;
        } else {
            if ($this->scheme) {
                return '//' . $this->authority;
            } else {
                return $this->authority;
            }
        }
    }
1305212
public function getAuthorizationUrl()
    {
        // Check for required items
        if (!$this->clientId) {
            throw new Exception('Client ID is required');
        }
        if (!$this->scope) {
            throw new Exception('Scope is required');
        }
        if (!$this->redirectUri) {
            throw new Exception('Redirect URI is required');
        }

        // Start building url (enpoint is the same for public and member APIs)
        $url  = 'https://';
        $url .= (!empty($this->environment)) ? $this->environment . '.' : '';
        $url .= self::HOSTNAME . '/' . self::AUTHORIZE;
        $url .= '?client_id='    . $this->clientId;
        $url .= '&scope='        . $this->scope;
        $url .= '&redirect_uri=' . urlencode($this->redirectUri);
        $url .= '&response_type=code';

        // Process non-required fields
        $url .= ($this->showLogin)          ? '&show_login=true'                    : '';
        $url .= (isset($this->state))       ? '&state=' . $this->state              : '';
        $url .= (isset($this->familyNames)) ? '&family_names=' . $this->familyNames : '';
        $url .= (isset($this->givenNames))  ? '&given_names=' . $this->givenNames   : '';
        $url .= (isset($this->email))       ? '&email=' . urlencode($this->email)   : '';

        return $url;
    }
1231211
public static function auth()
    {
        return function (callable $handler) {
            return function (RequestInterface $request, array $options) use ($handler) {
                if (empty($options['http_errors'])) {
                    return $handler($request, $options);
                }
                return $handler($request, $options)->then(
                    function (ResponseInterface $response) use ($request, $handler) {
                        $code = $response->getStatusCode();
                        if ($code == 401 || $code == 403) {
//							do your oauth authorization and retry
                            throw UnauthorizedException::create($request, $response);
                        }

                        return $response;
                    }
                );
            };
        };
    }
656284
private function buildRequestUrl()
    {
        if (!empty($_SERVER['REQUEST_URI'])) {
            return sprintf(
                '%s://%s%s%s',
                $this->guessProtocol(),
                $this->guessHost(),
                $this->guessPort(),
                $_SERVER['REQUEST_URI']
            );
        }
    }
182973
public function getAuthorizationURL($data = array())
    {
        if (version_compare($this->getVersion(), '1.0', '=')) {
            $response = $this->requestRequestToken();
            $data['oauth_token'] = $response->oauth_token;
        }
        
        $data = AnConfig::unbox($data);
        
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $data[ $key ] = implode(',', $value);
            }
        }
        
        $data = http_build_query($data);
        if (!empty($data)) {
            $data = '?'.$data;
        }
        
        return $this->authorize_url.$data;
    }
454276
public function request_token() {
        $this->sign_secret = $this->consumer_secret.'&';

        if (empty($this->oauth_callback)) {
            $params = [];
        } else {
            $params = ['oauth_callback' => $this->oauth_callback->out(false)];
        }

        $params = $this->prepare_oauth_parameters($this->request_token_api, $params, 'GET');
        $content = $this->http->get($this->request_token_api, $params, $this->http_options);
        // Including:
        //     oauth_token
        //     oauth_token_secret
        $result = $this->parse_result($content);
        if (empty($result['oauth_token'])) {
            throw new moodle_exception('oauth1requesttoken', 'core_error', '', null, $content);
        }
        // Build oauth authorize url.
        $result['authorize_url'] = $this->authorize_url . '?oauth_token='.$result['oauth_token'];

        return $result;
    }
552579
protected function buildRequest()
    {
        $request = new Request($this->helper());
        $request->setRouter($this->router());

        return $request;
    }
855959
final public static function getRequestURL()
	{
		$url = array_key_exists('REQUEST_SCHEME', $_SERVER)
			? "{$_SERVER['REQUEST_SCHEME']}://"
			: 'http://';
		if (array_key_exists('PHP_AUTH_USER', $_SERVER)) {
			$url .= static::URLEncode($_SERVER['PHP_AUTH_USER']);
			if (array_key_exists('PHP_AUTH_PW', $_SERVER)) {
				$url .= ':' . static::URLEncode($_SERVER['PHP_AUTH_PW']);
			}
			$url .= '@';
		}

		$url .= $_SERVER['HTTP_HOST'];
		$url .= $_SERVER[array_key_exists('REDIRECT_URL', $_SERVER) ? 'REDIRECT_URL' : 'REQUEST_URI'];

		return $url;
	}
213652
public function validateRequest()
    {
        $request = $this->framework->getRequest();
        
        // Parse the authorization information
        $authorization = $this->parseAuthorizationString($request->getHeader('Authorization'));
        $publicKey = $authorization['publicKey'];
        $hmac = $authorization['hmac'];
        
        // Verify the public key
        if (!$this->tokenManager->hasTokenForPublicKey($publicKey)) {
            return false;
        }
        
        // Load the token
        $token = $this->tokenManager->getTokenForPublicKey($publicKey);
        
        // Get the needed data
        $route = $request->getRoute();
        $data = $request->getParams();
        
        $result = $this->restHelper->validateRequest($token->getApiKey(), $hmac, $route, $data);
        
        if ($result) {
            return $token;
        }
        
        return false;
    }