|
UsingServiceTokenInModule
description of using a service token in a module
The Grant Proposal Application Module (itsprop) is required to do operations on the underlying DASe collection that the logged in user is not authorized to do. If the operations are done strictly within the handler (or other PHP code), we can simply embed the serviceuser and password in the code. But when the browser needs to do such operations, we need a (relatively) secure way for the browser to access the serviceuser password. The step are shown here.
({dase}/inc/local_config.php): $conf['serviceuser']['itsprop'] = 'ok' //'ok' can be anything that evaluates to true
public function getLogin($r)
{
$user = Uteid::login($r);
$secret = Dase_Auth::getSecret('itsprop');
Dase_Cookie::set('module',$secret);
...
}
<link rel="service_pass" href="{$module_root}service_pass/itsprop" />and here is the mapper & method: 'service_pass/{serviceuser}' => 'service_pass',public function getServicePass($r)
{
$secret = Dase_Cookie::get('module');
$suser = $r->get('serviceuser');
//checks the secret that was saved in cookie upon login
if ($secret == Dase_Auth::getSecret($r->get('serviceuser'))) {
//note: serviceuser MUST be declared in MODULE_ROOT.'/inc/config.php'
$r->renderResponse(Dase_Auth::getServicePassword($suser));
} else {
$r->renderError(401);
}
}
Dase.getServicePassword = function() {
var url = Dase.getLinkByRel('service_pass');
Dase.ajax(url,'get',function(resp) {
if (32 == resp.length) {
Dase.itsprop.service_pass = resp;
//any code that needs the service password must
//be initialized here
}
});
}
|
► Sign in to add a comment