TokenAuthenticationBase.php in RESTful 7.2
File
modules/restful_token_auth/src/Plugin/resource/TokenAuthenticationBase.php
View source
<?php
namespace Drupal\restful_token_auth\Plugin\resource;
use Drupal\restful\Plugin\resource\ResourceEntity;
use Drupal\restful\Plugin\resource\ResourceInterface;
abstract class TokenAuthenticationBase extends ResourceEntity implements ResourceInterface {
public function publicFields() {
$public_fields = parent::publicFields();
unset($public_fields['label']);
unset($public_fields['self']);
$public_fields['id']['methods'] = array();
$public_fields['access_token'] = array(
'property' => 'token',
);
$public_fields['type'] = array(
'callback' => array(
'\\Drupal\\restful\\RestfulManager::echoMessage',
array(
'Bearer',
),
),
);
$public_fields['expires_in'] = array(
'property' => 'expire',
'process_callbacks' => array(
'\\Drupal\\restful_token_auth\\Plugin\\resource\\TokenAuthenticationBase::intervalInSeconds',
),
);
$public_fields['refresh_token'] = array(
'property' => 'refresh_token_reference',
'process_callbacks' => array(
'\\Drupal\\restful_token_auth\\Plugin\\resource\\TokenAuthenticationBase::getTokenFromEntity',
),
);
return $public_fields;
}
public static function intervalInSeconds($value) {
$interval = $value - time();
return $interval < 0 ? 0 : $interval;
}
public static function getTokenFromEntity($token_id) {
if ($token = entity_load_single('restful_token_auth', $token_id)) {
return $token->token;
}
return NULL;
}
}