factory method for authentication gateway
@param string $authorizeUri
@param string $accessTokenUri
@param string $redirectUri
@throws \RuntimeException
@return \TheTwelve\Foursquare\AuthenticationGateway
543303
public function getAuthenticationGateway(
        $authorizeUri, $accessTokenUri, $redirectUri
    ) {

        if (!$this->redirector instanceof Redirector) {
            throw new \RuntimeException("A Redirector is required for authentication");
        }

        $gateway = new AuthenticationGateway($this->httpClient, $this->redirector);
        $gateway->setAuthorizeUri($authorizeUri)
                ->setAccessTokenUri($accessTokenUri)
                ->setRedirectUri($redirectUri)
                ->setClientCredentials($this->clientId, $this->clientSecret);

        return $gateway;

    }
354958
protected RedirectAction build(final CasClient casClient, final WebContext context, final boolean renew, final boolean gateway) {
        val serviceUrl = casClient.computeFinalCallbackUrl(context);
        val casServerLoginUrl = casClient.getConfiguration().getLoginUrl();
        val redirectionUrl = casServerLoginUrl + (casServerLoginUrl.contains("?") ? "&" : "?")
            + CasProtocolConstants.PARAMETER_SERVICE + '=' + EncodingUtils.urlEncode(serviceUrl)
            + (renew ? '&' + CasProtocolConstants.PARAMETER_RENEW + "=true" : StringUtils.EMPTY)
            + (gateway ? '&' + CasProtocolConstants.PARAMETER_GATEWAY + "=true" : StringUtils.EMPTY);
        LOGGER.debug("Final redirect url is [{}]", redirectionUrl);
        return RedirectAction.redirect(redirectionUrl);
    }
337345
public function remove($roleUri, $accessUri)
    {
        
		$uri = explode('#', $accessUri);
		list($type, $ext, $mod, $act) = explode('_', $uri[1]);
		
		$role = new \core_kernel_classes_Class($roleUri);
		$actionAccessProperty = new \core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS);
		
		$module = new \core_kernel_classes_Resource($this->makeEMAUri($ext, $mod));
		$controllerClassName = MapHelper::getControllerFromUri($module->getUri());
		
		// access via controller?
		$controllerAccess = CacheHelper::getControllerAccess($controllerClassName);
		if (in_array($roleUri, $controllerAccess['module'])) {

		    // remove access to controller
		    ModuleAccessService::singleton()->remove($roleUri, $module->getUri());
		
		    // add access to all other actions
		    foreach (ModelHelper::getActions($module) as $action) {
		        if ($action->getUri() != $accessUri) {
		            $this->add($roleUri, $action->getUri());
                    $this->getEventManager()->trigger(new AccessRightAddedEvent($roleUri, $action->getUri()));
                }
		    }
		    
		} elseif (isset($controllerAccess['actions'][$act]) && in_array($roleUri, $controllerAccess['actions'][$act])) {
		    // remove action only
		    $role->removePropertyValues($actionAccessProperty, array('pattern' => $accessUri));
            $this->getEventManager()->trigger(new AccessRightRemovedEvent($roleUri, $accessUri));

            CacheHelper::flushControllerAccess($controllerClassName);
		}
    }
1051096
public function remove($roleUri, $accessUri)
    {
        
		$uri = explode('#', $accessUri);
		list($type, $extId) = explode('_', $uri[1]);
		
		// Remove the access to the extension for this role.
		$extManager = \common_ext_ExtensionsManager::singleton();
		$extension = $extManager->getExtensionById($extId);
		$role = new \core_kernel_classes_Resource($roleUri);
		
		$role->removePropertyValues(new \core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS), array('pattern' => $accessUri));
        CacheHelper::flushExtensionAccess($extId);
		
		// also remove access to all the controllers
		$moduleAccessProperty = new \core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS);
		$moduleAccessService = ModuleAccessService::singleton();
		$grantedModules = $role->getPropertyValues($moduleAccessProperty);
		
		foreach ($grantedModules as $gM){
			$gM = new \core_kernel_classes_Resource($gM);
			$uri = explode('#', $gM->getUri());
			list($type, $ext) = explode('_', $uri[1]);
			
			if ($extId == $ext){
				$moduleAccessService->remove($role->getUri(), $gM->getUri());
                $this->getEventManager()->trigger(new AccessRightRemovedEvent($roleUri, $accessUri));
            }
		}
		
    }
442103
public static function accessDenied($hint = null, $redirectUri = null, Throwable $previous = null)
    {
        return new static(
            'The resource owner or authorization server denied the request.',
            9,
            'access_denied',
            401,
            $hint,
            $redirectUri,
            $previous
        );
    }
15747
public static OAuthClientRequest getAuthorizationRequest(String clientId, String redirectUri)
            throws OAuthSystemException {
        return OAuthClientRequest
                .authorizationLocation(OAUTH2_AUTHORIZATION_URL)
                .setScope("public read write")
                .setResponseType(ResponseType.CODE.toString())
                .setClientId(clientId)
                .setRedirectURI(redirectUri)
                .buildQueryMessage();
    }
1213157
public function createToken($redirectUri, $owner, $client, array $scopes = []): AuthorizationCode
    {
        if (empty($scopes)) {
            $scopes = $this->scopeService->getDefaultScopes();
        } else {
            $this->validateTokenScopes($scopes);
        }

        do {
            $token = AuthorizationCode::createNewAuthorizationCode(
                $this->serverOptions->getAuthorizationCodeTtl(),
                $redirectUri,
                $owner,
                $client,
                $scopes
            );
        } while ($this->tokenRepository->tokenExists($token->getToken()));

        return $this->tokenRepository->save($token);
    }
140441
protected function createRedirectTokenResponse(
        TokenInterface $token,
        int $tokenExpiresIn,
        string $state = null
    ): ResponseInterface {
        $this->logDebug('Sending token as redirect response.');

        $scopeList  = $token->isScopeModified() === false || empty($token->getScopeIdentifiers()) === true ?
            null : $token->getScopeList();

        // for access token format @link https://tools.ietf.org/html/rfc6749#section-5.1
        $parameters = $this->filterNulls([
            'access_token' => $token->getValue(),
            'token_type'   => $token->getType(),
            'expires_in'   => $tokenExpiresIn,
            'scope'        => $scopeList,
            'state'        => $state,
        ]);

        $fragment = $this->encodeAsXWwwFormUrlencoded($parameters);

        $response = new RedirectResponse((new Uri($token->getRedirectUriString()))->withFragment($fragment));

        return $response;
    }
622742
public function getAuthUri($state, $redirectUri, array $scopes = array())
    {
        $params = array(
            'response_type' => 'code',
            'client_id' => $this->credentialsId,
            'scope' => implode(' ', $scopes),
            'redirect_uri' => $redirectUri,
            'state' => $state,
        );
        return $this->authEndpoint . (strpos($this->authEndpoint, '?') === false ? '?' : '&')
            . http_build_query($params, null, '&');
    }
940417
public Credential authenticate(String authorizationCode, String userId) throws AuthException {
        Preconditions.checkNotNull(authorizationCode, "Authorization code must not be null");
        AuthorizationCodeTokenRequest tokenRequest = authorizationCodeFlow.newTokenRequest(authorizationCode);

        TokenResponse tokenResponse;
        try {
            tokenResponse = tokenRequest
                    .setRedirectUri(redirectUri)
                    .setScopes(scopes)
                    .execute();
        } catch (IOException e) {
            throw new AuthException("Unable to request token.", e);
        }
        try {
            return authorizationCodeFlow.createAndStoreCredential(tokenResponse, userId);
        } catch (IOException e) {
            throw new AuthException("Unable to create and store credential.", e);
        }
    }
704288
public void configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) {
    for(Authentication auth : authentications.values()) {
      if (auth instanceof OAuth) {
        OAuth oauth = (OAuth) auth;
        oauth.getTokenRequestBuilder()
              .setClientId(clientId)
              .setClientSecret(clientSecret)
              .setRedirectURI(redirectURI);
        oauth.getAuthenticationRequestBuilder()
              .setClientId(clientId)
              .setRedirectURI(redirectURI);
        return;
      }
    }
  }
1299798
def authorize(self, code):
        
        if self._authenticator.redirect_uri is None:
            raise InvalidInvocation("redirect URI not provided")
        self._request_token(
            code=code,
            grant_type="authorization_code",
            redirect_uri=self._authenticator.redirect_uri,
        )
284628
private function buildRedirect( $redirectUrl, $redirectCode )
	{
		if ( is_null( $redirectCode ) )
		{
			return new Redirect( $redirectUrl );
		}
		else
		{
			return new Redirect( $redirectUrl, $redirectCode );
		}
	}
1077105
public static OAuthRegisteredService getRegisteredOAuthServiceByRedirectUri(final ServicesManager servicesManager, final String redirectUri) {
        return getRegisteredOAuthServiceByPredicate(servicesManager, s -> s.matches(redirectUri));
    }
579341
protected URI determineUnauthorizedServiceRedirectUrl(final RequestContext context) {
        val redirectUrl = WebUtils.getUnauthorizedRedirectUrlFromFlowScope(context);
        val currentEvent = context.getCurrentEvent();
        val eventAttributes = currentEvent.getAttributes();
        LOGGER.debug("Finalizing the unauthorized redirect URL [{}] when processing event [{}] with attributes [{}]",
            redirectUrl, currentEvent.getId(), eventAttributes);
        return redirectUrl;
    }
1325226
protected function codeAskResourceOwnerForApproval(
        array $parameters,
        ClientInterface $client,
        string $redirectUri = null,
        int $maxStateLength = null
    ): ResponseInterface {
        $state = $this->codeGetState($parameters);
        if ($maxStateLength !== null && strlen($state) > $maxStateLength) {
            throw new OAuthCodeRedirectException(
                OAuthCodeRedirectException::ERROR_INVALID_REQUEST,
                $redirectUri,
                $state
            );
        }

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

        $scope = $this->codeGetScope($parameters);
        list ($isScopeValid, $scopeList, $isScopeModified) =
            $this->codeGetIntegration()->codeValidateScope($client, $scope);
        if ($isScopeValid === false) {
            throw new OAuthCodeRedirectException(
                OAuthCodeRedirectException::ERROR_INVALID_SCOPE,
                $redirectUri,
                $state
            );
        }

        $response = $this->codeGetIntegration()->codeCreateAskResourceOwnerForApprovalResponse(
            $client,
            $redirectUri,
            $isScopeModified,
            $scopeList,
            $state
        );

        return $response;
    }
886870
def authorization_link(self, redirect_uri):
        '''
        '''
        args = '?client_id=%s&redirect_uri=%s' % (
            self.app_key,
            redirect_uri
        )
        uri = "/".join([BASE_URL, API_VERSION, OAUTH, args])
        return uri