<table>
  <base>CRM/OAuth</base>
  <class>OAuthContactToken</class>
  <name>civicrm_oauth_contact_token</name>
  <add>5.35</add>
  <field>
    <name>id</name>
    <title>Token ID</title>
    <type>int unsigned</type>
    <required>true</required>
    <comment>Token ID</comment>
    <add>5.35</add>
  </field>
  <primaryKey>
    <name>id</name>
    <autoincrement>true</autoincrement>
  </primaryKey>

  <!-- Details based on how the token was requested -->

  <field>
    <name>tag</name>
    <title>Tag</title>
    <type>varchar</type>
    <length>128</length>
    <comment>The tag specifies how this token will be used.</comment>
    <add>5.35</add>
  </field>
  <index>
    <name>UI_tag</name>
    <fieldName>tag</fieldName>
    <add>5.35</add>
  </index>

  <field>
    <name>client_id</name>
    <title>Client ID</title>
    <type>int unsigned</type>
    <comment>Client ID</comment>
    <add>5.35</add>
  </field>
  <foreignKey>
    <name>client_id</name>
    <table>civicrm_oauth_client</table>
    <key>id</key>
    <add>5.35</add>
    <onDelete>CASCADE</onDelete>
  </foreignKey>

  <field>
    <name>contact_id</name>
    <title>Contact ID</title>
    <type>int unsigned</type>
    <comment>Contact ID</comment>
    <add>5.35</add>
  </field>
  <foreignKey>
    <name>contact_id</name>
    <table>civicrm_contact</table>
    <key>id</key>
    <add>5.35</add>
    <onDelete>CASCADE</onDelete>
  </foreignKey>

  <field>
    <name>grant_type</name>
    <title>Grant type</title>
    <type>varchar</type>
    <length>31</length>
    <!-- FIXME: Pseudoconstant -->
    <comment>Ex: authorization_code</comment>
    <add>5.35</add>
  </field>

  <field>
    <name>scopes</name>
    <type>text</type>
    <comment>List of scopes addressed by this token</comment>
    <serialize>SEPARATOR_BOOKEND</serialize>
    <add>5.35</add>
  </field>

  <!-- Data provided by the authentication server -->

  <field>
    <name>token_type</name>
    <title>Token Type</title>
    <type>varchar</type>
    <length>128</length>
    <comment>Ex: Bearer or MAC</comment>
    <add>5.35</add>
  </field>

  <field>
    <name>access_token</name>
    <title>Access Token</title>
    <type>text</type>
    <!-- text or varchar? In theory, if the auth svc uses JWT, tokens can get long -->
    <comment>Token to present when accessing resources</comment>
    <add>5.35</add>
  </field>

  <field>
    <name>expires</name>
    <type>int unsigned</type>
    <title>Expiration time</title>
    <default>0</default>
    <comment>Expiration time for the access_token (seconds since epoch)</comment>
    <add>5.35</add>
  </field>

  <field>
    <name>refresh_token</name>
    <title>Refresh Token</title>
    <type>text</type>
    <!-- text or varchar? In theory, if the auth svc uses JWT, tokens can get long -->
    <comment>Token to present when refreshing the access_token</comment>
    <add>5.35</add>
  </field>

  <field>
    <name>resource_owner_name</name>
    <title>Resource Owner Name</title>
    <type>varchar</type>
    <length>128</length>
    <comment>Identifier for the resource owner. Structure varies by service.</comment>
    <add>5.35</add>
  </field>

  <field>
    <name>resource_owner</name>
    <title>Resource Owner</title>
    <type>text</type>
    <comment>Cached details describing the resource owner</comment>
    <serialize>JSON</serialize>
    <add>5.35</add>
  </field>

  <field>
    <name>error</name>
    <type>text</type>
    <comment>?? copied from OAuthSysToken</comment>
    <serialize>JSON</serialize>
    <add>5.35</add>
  </field>

  <field>
    <name>raw</name>
    <title>Raw token</title>
    <type>text</type>
    <serialize>JSON</serialize>
    <comment>The token response data, per AccessToken::jsonSerialize</comment>
    <add>5.35</add>
  </field>

  <!-- Lifecycle -->

  <field>
    <name>created_date</name>
    <type>timestamp</type>
    <comment>When the token was created.</comment>
    <required>false</required>
    <default>CURRENT_TIMESTAMP</default>
    <add>5.35</add>
  </field>
  <field>
    <name>modified_date</name>
    <type>timestamp</type>
    <comment>When the token was created or modified.</comment>
    <required>false</required>
    <default>CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP</default>
    <add>5.35</add>
  </field>

</table>
