class AccessToken__1_0 in RESTful 7.2
Class AccessToken__1_0 @package Drupal\restful_token_auth\Plugin\resource
Plugin annotation
@Resource(
name = "access_token:1.0",
resource = "access_token",
label = "Access token authentication",
description = "Export the access token authentication resource.",
authenticationTypes = {
"cookie",
"basic_auth"
},
authenticationOptional = FALSE,
dataProvider = {
"entityType": "restful_token_auth",
"bundles": {
"access_token"
},
},
formatter = "single_json",
menuItem = "login-token",
majorVersion = 1,
minorVersion = 0
)
Hierarchy
- class \Drupal\restful\Plugin\resource\Resource extends \Drupal\Component\Plugin\PluginBase implements ResourceInterface uses ConfigurablePluginTrait
- class \Drupal\restful\Plugin\resource\ResourceEntity
- class \Drupal\restful_token_auth\Plugin\resource\TokenAuthenticationBase implements ResourceInterface
- class \Drupal\restful_token_auth\Plugin\resource\AccessToken__1_0 implements ResourceInterface
- class \Drupal\restful_token_auth\Plugin\resource\TokenAuthenticationBase implements ResourceInterface
- class \Drupal\restful\Plugin\resource\ResourceEntity
Expanded class hierarchy of AccessToken__1_0
File
- modules/
restful_token_auth/ src/ Plugin/ resource/ AccessToken__1_0.php, line 40 - Contains Drupal\restful_token_auth\Plugin\resource\AccessToken__1_0.
Namespace
Drupal\restful_token_auth\Plugin\resourceView source
class AccessToken__1_0 extends TokenAuthenticationBase implements ResourceInterface {
/**
* {@inheritdoc}
*/
public function controllersInfo() {
return array(
'' => array(
// Get or create a new token.
RequestInterface::METHOD_GET => 'getOrCreateToken',
RequestInterface::METHOD_OPTIONS => 'discover',
),
);
}
/**
* Create a token for a user, and return its value.
*/
public function getOrCreateToken() {
$entity_type = $this
->getEntityType();
$account = $this
->getAccount();
// Check if there is a token that did not expire yet.
/* @var DataProviderEntityInterface $data_provider */
$data_provider = $this
->getDataProvider();
$query = $data_provider
->EFQObject();
$result = $query
->entityCondition('entity_type', $entity_type)
->entityCondition('bundle', 'access_token')
->propertyCondition('uid', $account->uid)
->range(0, 1)
->execute();
$token_exists = FALSE;
if (!empty($result[$entity_type])) {
$id = key($result[$entity_type]);
$access_token = entity_load_single($entity_type, $id);
$token_exists = TRUE;
if (!empty($access_token->expire) && $access_token->expire < REQUEST_TIME) {
if (variable_get('restful_token_auth_delete_expired_tokens', TRUE)) {
// Token has expired, so we can delete this token.
$access_token
->delete();
}
$token_exists = FALSE;
}
}
if (!$token_exists) {
/* @var \Drupal\restful_token_auth\Entity\RestfulTokenAuthController $controller */
$controller = entity_get_controller($this
->getEntityType());
$access_token = $controller
->generateAccessToken($account->uid);
$id = $access_token->id;
}
$output = $this
->view($id);
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessToken__1_0:: |
public | function |
Gets the controllers. Overrides Resource:: |
|
AccessToken__1_0:: |
public | function | Create a token for a user, and return its value. | |
ConfigurablePluginTrait:: |
protected | property | Plugin instance configuration. | |
ConfigurablePluginTrait:: |
public | function | ||
ConfigurablePluginTrait:: |
public | function | ||
ConfigurablePluginTrait:: |
public | function | ||
Resource:: |
protected | property | The authentication manager. | |
Resource:: |
protected | property | The data provider. | |
Resource:: |
protected | property | Indicates if the resource is enabled. | |
Resource:: |
protected | property | The field definition object. | |
Resource:: |
protected | property | The requested path. | |
Resource:: |
protected | property | The current request. | |
Resource:: |
public | function |
Determine if user can access the handler. Overrides ResourceInterface:: |
1 |
Resource:: |
protected | function | Checks access based on the referer header and the allowOrigin setting. | |
Resource:: |
public | function |
Basic implementation for create. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Overrides ConfigurablePluginTrait:: |
|
Resource:: |
public | function |
Disable the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Discovery controller callback. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick DELETE request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick GET request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick PATCH request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick POST request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick PUT request. Overrides ResourceInterface:: |
|
Resource:: |
private | function | ||
Resource:: |
public | function |
Enable the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Get the user from for request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Return the controller for a given path. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the controllers for this resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the data provider. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the field definitions. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the path of the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Get the request object. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the resource machine name. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the resource name. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Helper method; Get the URL of the resource and query strings. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Return array keyed with the major and minor version of the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Basic implementation for listing. Overrides ResourceInterface:: |
1 |
Resource:: |
protected | function | Initializes the authentication manager and adds the appropriate providers. | |
Resource:: |
public | function |
Checks if the resource is enabled. Overrides ResourceInterface:: |
|
Resource:: |
protected | function | Adds the Allowed-Origin headers. | |
Resource:: |
public | function |
Controller function that passes the data along and executes right action. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Basic implementation for update. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Basic implementation for update. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the data provider. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the field definitions. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the path of the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the plugin definition to the provided array. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the request object. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Switches the user back from the original user for the session. Overrides ResourceInterface:: |
1 |
Resource:: |
public | function |
Basic implementation for update. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets a resource URL based on the current version. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Basic implementation for view. Overrides ResourceInterface:: |
|
ResourceEntity:: |
protected | property | The entity bundles. | |
ResourceEntity:: |
protected | property | The entity type. | |
ResourceEntity:: |
protected | function |
Data provider class. Overrides Resource:: |
3 |
ResourceEntity:: |
public | function |
Data provider factory. Overrides Resource:: |
|
ResourceEntity:: |
public | function | Gets the entity bundle. | |
ResourceEntity:: |
public | function | Get the "self" url. | |
ResourceEntity:: |
public | function | Gets the entity type. | |
ResourceEntity:: |
protected | function |
Get the public fields with the default values applied to them. Overrides Resource:: |
2 |
ResourceEntity:: |
protected | function | Get the public fields with default values based on view mode information. | |
ResourceEntity:: |
public | function |
Constructs a Drupal\Component\Plugin\PluginBase object. Overrides Resource:: |
2 |
ResourceInterface:: |
constant | The string that separates multiple ids. | ||
TokenAuthenticationBase:: |
public static | function | Get the token string from the token entity. | |
TokenAuthenticationBase:: |
public static | function | Process callback helper to get the time difference in seconds. | |
TokenAuthenticationBase:: |
public | function |
Overrides ResourceEntity::publicFields(). Overrides ResourceEntity:: |