You are here

function oauth2_server_schema in OAuth2 Server 7

Implements hook_schema().

1 call to oauth2_server_schema()
oauth2_server_update_7100 in ./oauth2_server.install
Adds the {oauth2_server_jti} table, {oauth2_server_client}.public_key field.

File

./oauth2_server.install, line 53

Code

function oauth2_server_schema() {
  $schema['oauth2_server'] = array(
    'description' => 'The base table for servers.',
    'fields' => array(
      'server_id' => array(
        'description' => 'Primary key: numeric server id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The machine name for a server.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'label' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'The label of the server.',
        'default' => '',
      ),
      'settings' => array(
        'description' => 'Settings passed to the server library.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // Set the default to ENTITY_CUSTOM without using the constant as it is
        // not safe to use it at this point.
        'default' => 0x1,
        'size' => 'tiny',
        'description' => 'The exportable status of the server.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the server has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'server_id',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['oauth2_server_scope'] = array(
    'description' => 'The base table for scopes.',
    'fields' => array(
      'scope_id' => array(
        'description' => 'Primary key: numeric scope id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'server' => array(
        'description' => 'The {oauth2_server}.name of the parent server.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The machine name of the scope.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'description' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'The description used to describe the scope on the authorization form.',
        'default' => '',
      ),
    ),
    'primary key' => array(
      'scope_id',
    ),
    'indexes' => array(
      'name' => array(
        'name',
      ),
      'server' => array(
        'server',
      ),
    ),
  );
  $schema['oauth2_server_client'] = array(
    'description' => 'The base table for clients',
    'fields' => array(
      'client_id' => array(
        'description' => 'Primary key: numeric client id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'server' => array(
        'description' => 'The {oauth2_server}.name of the parent server.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => 'The label of the client.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      // The OAuth2 spec calls the client key "client_id", but we need that
      // for the autoincrement.
      'client_key' => array(
        'description' => 'The client key',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'client_secret' => array(
        'description' => 'The client secret.',
        'type' => 'text',
        'not null' => TRUE,
      ),
      'public_key' => array(
        'description' => 'The public key.',
        'type' => 'text',
        'not null' => TRUE,
      ),
      'redirect_uri' => array(
        'description' => 'The absolute URI to redirect to after authorization',
        'type' => 'text',
        'not null' => TRUE,
      ),
      'automatic_authorization' => array(
        'description' => 'Whether authorization should be completed without user confirmation.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'settings' => array(
        'description' => 'Client specific settings.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'client_id',
    ),
    'unique keys' => array(
      'client_key' => array(
        'client_key',
      ),
    ),
    'indexes' => array(
      'server' => array(
        'server',
      ),
    ),
  );
  $schema['oauth2_server_authorization_code'] = array(
    'description' => 'The base table for authorization codes',
    'fields' => array(
      'code_id' => array(
        'description' => 'Primary key: numeric code id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'client_id' => array(
        'description' => 'The {oauth2_server_client}.client_id of the client.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'The {users}.uid of the resource owner.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'code' => array(
        'description' => 'The authorization code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'redirect_uri' => array(
        'description' => 'The absolute URI to redirect to after authorization',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'expires' => array(
        'description' => 'The Unix timestamp when the token expires.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'id_token' => array(
        'description' => 'The id token, if OpenID Connect was used.',
        'type' => 'text',
      ),
    ),
    'primary key' => array(
      'code_id',
    ),
    'unique keys' => array(
      'code' => array(
        'code',
      ),
    ),
  );
  $schema['oauth2_server_token'] = array(
    'description' => 'The base table for tokens',
    'fields' => array(
      'token_id' => array(
        'description' => 'Primary key: numeric token id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'client_id' => array(
        'description' => 'The {oauth2_server_client}.client_id of the client.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'The {users}.uid of the resource owner.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'type' => array(
        'description' => 'The type of the token (access, refresh).',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'token' => array(
        'description' => 'The token.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'expires' => array(
        'description' => 'The Unix timestamp when the token expires.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_access' => array(
        'description' => 'The Unix timestamp when the token was last used.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the token was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'token_id',
    ),
    'unique keys' => array(
      'token' => array(
        'token',
      ),
    ),
  );
  $schema['oauth2_server_jti'] = array(
    'description' => 'Stores JSON Token Identifiers, used to prevent JWT replay attacks.',
    'fields' => array(
      'jti_id' => array(
        'description' => 'Primary key: numeric JTI id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'client_id' => array(
        'description' => 'The {oauth2_server_client}.client_id of the client.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'subject' => array(
        'description' => 'The JWT subject, usually a username or email.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'jti' => array(
        'description' => 'The JSON Token Identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'expires' => array(
        'description' => 'The Unix timestamp when the JTI expires.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'jti_id',
    ),
  );
  return $schema;
}