PHP code example of wwtg99 / pgauth

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

    

wwtg99 / pgauth example snippets


$pool = new \Wwtg99\DataPool\Common\DefaultDataPool('../conf.json');
$conn = $pool->getConnection('main');
$config = [
    "cache"=>[
        "type"=>"redis",
        "options"=>[
            "schema"=>"tcp",
            "host"=>"192.168.83.128",
            "database"=>4
        ]
    ],
    'auth_method'=>7,
    'token_ttl'=>60,
    'code_ttl'=>60
];
$appu = new \Wwtg99\PgAuth\Utils\AppUtils($conn);
//step 1 get code
$user1 = ['username'=>'u1', 'password'=>'2'];
$aid = 'asfafs';
$redirect_uri = 'localhost';
$auth = new \Wwtg99\PgAuth\Auth\NormalAuth($conn, $config);
$oauth = new \Wwtg99\PgAuth\Utils\OAuthUtils($config);
$code = '';
$app = $appu->verifyAppIdUri($aid, $redirect_uri);
if ($app) {
    $u = $auth->signIn($user1);
    if ($u) {
        $code = $oauth->generateCode($u->getUserArray(), $aid, $redirect_uri);
        echo "\nCode: $code";
    }
}
//step 2 get access_token
$secret = 'fasf3wfsdf';
$u = $oauth->verifyCode($code);
if ($u) {
    $aid = $u['app_id'];
    $re = $appu->verifySecret($aid, $secret);
    if ($re) {
        $token = $u['access_token'];
        echo "\nUser: ";
        print_r($u);
    }
}

// create role
$role = $this->pool->getConnection('main')->getMapper('Role');
$data = ['name'=>'r1', 'descr'=>'rrr'];
$rid = $role->insert($data);
// update role
$data_update = ['name'=>'role1', 'descr'=>'ggg'];
$re = $role->update($data_update, null, $rid);
// get all roles
$re = $role->select();
// get role by id
$re = $role->get($rid);
// delete role
$re = $role->delete($rid);

// create app
$app = $this->pool->getConnection('main')->getMapper('App');
$data = ['app_name'=>'app1', 'descr'=>'rrr', 'redirect_uri'=>'localhost'];
$aid = $app->insert($data);
// update app
$data_update = ['app_name'=>'app11', 'descr'=>'ggg'];
$re = $app->update($data_update, null, $aid);
// get all app
$re = $app->select();
// get app by id
$re = $app->get($aid);
// delete app
$re = $app->delete($aid);