PHP code example of reb3r / oauth2-server-httpfoundation-bridge

1. Go to this page and download the library: Download reb3r/oauth2-server-httpfoundation-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reb3r / oauth2-server-httpfoundation-bridge example snippets


$request = OAuth2\HttpFoundationBridge\Request::createFromGlobals();
$app->run($request);

// getBaseUrl is unique to HttpFoundation
$baseUrl = $request->getBaseUrl();

// call oauth server
$server->grantAccessToken($request);

use OAuth2\HttpFoundationBridge\Request as BridgeRequest;

// in your controller layer, the $request object is passed in
public function execute(Request $request)
{
    //... (instantiate server/response objects)
    $bridgeRequest = BridgeRequest::createFromRequest($request);
    $server->grantAccessToken($bridgeRequest, $response);
}

use OAuth2\HttpFoundationBridge\Response as BridgeResponse;

// in your controller layer, the $request object is passed in
public function execute(Request $request)
{
    //... (instantiate server/response objects)
    $response = new BridgeResponse();
    return $server->handleTokenRequest($request, $response);
}