public function authenticate(HTTPRequest $request)
    {
        $providerName = $request->getVar('provider');
        $context = $request->getVar('context');
        $scope = $request->getVar('scope');

        // Missing or invalid data means we can't proceed
        if (!$providerName || !is_array($scope)) {
            $this->httpError(404);
            return null;
        }

        /** @var ProviderFactory $providerFactory */
        $providerFactory = Injector::inst()->get(ProviderFactory::class);
        $provider = $providerFactory->getProvider($providerName);
        $url = $provider->getAuthorizationUrl(['scope' => $scope]);

        $request->getSession()->set('oauth2', [
            'state' => $provider->getState(),
            'provider' => $providerName,
            'context' => $context,
            'scope' => $scope,
            'backurl' => $this->findBackUrl($request)
        ]);

        return $this->redirect($url);
    }
public function authenticate(HTTPRequest $request)
    {
        $providerName = $request->getVar('provider');
        $context = $request->getVar('context');
        $scope = $request->getVar('scope');

        // Missing or invalid data means we can't proceed
        if (!$providerName || !is_array($scope)) {
            $this->httpError(404);
            return null;
        }

        /** @var ProviderFactory $providerFactory */
        $providerFactory = Injector::inst()->get(ProviderFactory::class);
        $provider = $providerFactory->getProvider($providerName);
        $url = $provider->getAuthorizationUrl(['scope' => $scope]);

        $request->getSession()->set('oauth2', [
            'state' => $provider->getState(),
            'provider' => $providerName,
            'context' => $context,
            'scope' => $scope,
            'backurl' => $this->findBackUrl($request)
        ]);

        return $this->redirect($url);
    }
public function authenticate ( HTTPRequest $ request ) { $ providerName = $ request -> getVar ( 'provider' ) ; $ context = $ request -> getVar ( 'context' ) ; $ scope = $ request -> getVar ( 'scope' ) ; // Missing or invalid data means we can't proceed if ( ! $ providerName || ! is_array ( $ scope ) ) { $ this -> httpError ( 404 ) ; return null ; } /** @var ProviderFactory $providerFactory */ $ providerFactory = Injector :: inst ( ) -> get ( ProviderFactory :: class ) ; $ provider = $ providerFactory -> getProvider ( $ providerName ) ; $ url = $ provider -> getAuthorizationUrl ( [ 'scope' => $ scope ] ) ; $ request -> getSession ( ) -> set ( 'oauth2' , [ 'state' => $ provider -> getState ( ) , 'provider' => $ providerName , 'context' => $ context , 'scope' => $ scope , 'backurl' => $ this -> findBackUrl ( $ request ) ] ) ; return $ this -> redirect ( $ url ) ; }
This takes parameters like the provider, scopes and callback url, builds an authentication
url with the provider's site and then redirects to it

@todo allow whitelisting of scopes (per provider)?
@param HTTPRequest $request
@return HTTPResponse
@throws HTTPResponse_Exception
This takes parameters like the provider scopes and callback url builds an authentication url with the provider s site and then redirects to it