PHP code example of hpdc / sdk

1. Go to this page and download the library: Download hpdc/sdk 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/ */

    

hpdc / sdk example snippets




namespace App\Http\Controllers;

use Hpdc\Authentication;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Authentication client.
     * 
     * @var \Hpdc\Authentication
     */
    protected $client;

    /**
     * Instantiate the controller.
     * 
     * @param \Hpdc\Authentication $auth
     */
    public function __construct(Authentication $auth)
    {
    	// Set your local client property.
    	$this->client = $auth;

    	/*
    	|--------------------------------------------------------------------------
    	| Set Required Configuration Variables
    	|--------------------------------------------------------------------------
    	|
    	| The Authentication SDK    return redirect('/');
    }

    /**
     * Build the authorize query and redirect to API.
     * 
     * @return response
     */
    public function auth()
    {
    	$url = $this->client->make();

    	return redirect($url);
    }

    /**
     * Send a token request and store the credentials in your session,
     * then redirect the user back to a selected page.
     * 
     * @param  \Illuminate\Http\Request  $request
     * @return response
     */
    public function callback(Request $request)
    {
        // code variable returned from OAuth
        // capture this from your request object
        $code = $request->code;

        // retrieve your token
        $response = $this->client->send($code);

        // store the token in your session
        session(['api'       => $response]);
        session(['api-token' => $response['access_token']]);

        return redirect('/');
    }
}