public function authenticate(HTTPRequest $request): HTTPRequest
    {
        $requestAdapter = new HttpRequestAdapter();
        $responseAdapter = new HttpResponseAdapter();

        // missing vars (cli)
        $this->addMissingServerVariables($requestAdapter);

        $server = $this->getServer();
        $psrRequest = $requestAdapter->toPsr7($request);
        $psrResponse = new Response();

        try {
            $psrRequest = $server->validateAuthenticatedRequest($psrRequest);
        } catch (OAuthServerException $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7($exception->generateHttpResponse($psrResponse))
            );
        } catch (\Exception $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7(
                    (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))
                        ->generateHttpResponse($psrResponse)
                )
            );
        }
        // add the request attributes as custom auth headers
        foreach ($psrRequest->getAttributes() as $attribute => $value) {
            $request->addHeader($attribute, $value);
        }

        return $request;
    }
public function authenticate(HTTPRequest $request): HTTPRequest
    {
        $requestAdapter = new HttpRequestAdapter();
        $responseAdapter = new HttpResponseAdapter();

        // missing vars (cli)
        $this->addMissingServerVariables($requestAdapter);

        $server = $this->getServer();
        $psrRequest = $requestAdapter->toPsr7($request);
        $psrResponse = new Response();

        try {
            $psrRequest = $server->validateAuthenticatedRequest($psrRequest);
        } catch (OAuthServerException $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7($exception->generateHttpResponse($psrResponse))
            );
        } catch (\Exception $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7(
                    (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))
                        ->generateHttpResponse($psrResponse)
                )
            );
        }
        // add the request attributes as custom auth headers
        foreach ($psrRequest->getAttributes() as $attribute => $value) {
            $request->addHeader($attribute, $value);
        }

        return $request;
    }
public function authenticate ( HTTPRequest $ request ) : HTTPRequest { $ requestAdapter = new HttpRequestAdapter ( ) ; $ responseAdapter = new HttpResponseAdapter ( ) ; // missing vars (cli) $ this -> addMissingServerVariables ( $ requestAdapter ) ; $ server = $ this -> getServer ( ) ; $ psrRequest = $ requestAdapter -> toPsr7 ( $ request ) ; $ psrResponse = new Response ( ) ; try { $ psrRequest = $ server -> validateAuthenticatedRequest ( $ psrRequest ) ; } catch ( OAuthServerException $ exception ) { // convert to authentication exception throw new AuthenticationException ( $ exception -> getMessage ( ) , $ exception -> getCode ( ) , $ responseAdapter -> fromPsr7 ( $ exception -> generateHttpResponse ( $ psrResponse ) ) ) ; } catch ( \ Exception $ exception ) { // convert to authentication exception throw new AuthenticationException ( $ exception -> getMessage ( ) , $ exception -> getCode ( ) , $ responseAdapter -> fromPsr7 ( ( new OAuthServerException ( $ exception -> getMessage ( ) , 0 , 'unknown_error' , 500 ) ) -> generateHttpResponse ( $ psrResponse ) ) ) ; } // add the request attributes as custom auth headers foreach ( $ psrRequest -> getAttributes ( ) as $ attribute => $ value ) { $ request -> addHeader ( $ attribute , $ value ) ; } return $ request ; }
Authenticate the request. Adds oauth fields as headers on the request.

@param HTTPRequest $request The SilverStripe request object to be authenticated.

@return HTTPRequest
@throws AuthenticationException
Authenticate the request . Adds oauth fields as headers on the request .