When trying to obtain an access token, with cryptotokens enabled, i get this error:

PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'token' at row 1: INSERT INTO {oauth2_server_token} (client_id, uid, type, token, expires) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array
(
    [:db_insert_placeholder_0] => 1
    [:db_insert_placeholder_1] => 1
    [:db_insert_placeholder_2] => access
    [:db_insert_placeholder_3] => eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpZCI6ImQ0YjNmNzlkM2VmMTBlZmFhN2U1MmQxZTAzYmY1NTgzMzA3ZDIyNTMiLCJjbGllbnRfaWQiOiJiaGFwaSIsInVzZXJfaWQiOiJhZG1pbiIsImV4cGlyZXMiOjE0MjE0OTc2MzIsInRva2VuX3R5cGUiOiJiZWFyZXIiLCJzY29wZSI6InVzZXJfcHJvZmlsZSJ9.cXzgfQOUJ16CPtvl8K--QmKYg3En_7gAzMoiND1qSxU5cm2iMTo3QV1gz6gIIC2TJWSWJbKUxB41bN84PkTMBA1AwFuNC76zvLWdztXYxcEDalNzTVdE5Smw8ad3H-J8a9NIc0D0ZeINvcBeeewNG9-vYQFBZdoEsuQH87BuXjNV8oQDzwCCb2m9s35nemdbDhIoVEajM0Y2NRJmN_SRvqGhHZAOtaoNUXGenPKbxsjrJGhtksdqOLhl70IO1fcsSQWrlOFllW57EXWflkVapcMSn0IYDArTJEDcDc2qT8MSL7ig4hgqa9eVEZiIQa-fXvdMlxdo8kB6WONUhI9uMQ
    [:db_insert_placeholder_4] => 1421497632
)
 in drupal_write_record() (line 7239 of /var/sites/default/public/includes/common.inc).

If i disable crypto tokens i get no errors and everything appears to work correctly.

See full output here: http://pastebin.com/jkA053Bk

Comments

pjcdawkins’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new944 bytes

This may or may not be the right solution.

pjcdawkins’s picture

Status: Needs review » Needs work

The JWTs are not supposed to be stored in the database at all

pjcdawkins’s picture

Status: Needs work » Postponed (maintainer needs more info)

There is already a test case which would catch this error if merely enabling JWT (crypto) tokens was enough to reproduce it.

http://cgit.drupalcode.org/oauth2_server/tree/tests/oauth2_server.test#n582

So I suspect there is some other issue.

jdiggety’s picture

Encountered same issue. Logged in here https://www.drupal.org/node/2496219, but closed once I realised was duplicate.

Running with patch at this time, but agreed that there is no need to store JWTs in DB in the first place.

spdaly’s picture

Agree. No need to store JWT in DB.

spdaly’s picture

So the attached patch will not work - at least with MySQL. The token field is a key in one of the indexes. When you try to alter the table like the patch, you will get an error message "BLOB/TEXT column 'token' used in key specification without a key length." You cannot put a length on a TEXT field. http://stackoverflow.com/questions/1827063/mysql-error-key-specification....

I don't have a patch file for this, but you will need to remove the token index from the table. Change the table structure (set token field to text type). And then recreate the token index using the first 255 characters of the text field.

spdaly’s picture

StatusFileSize
new723 bytes

Here's the patch.

It drops the token index. Alters the table. Recreates the token index.

pjcdawkins’s picture

Status: Postponed (maintainer needs more info) » Needs work

That patch might be a workaround but the root issue (JWTs should not have storage) needs fixing too

pwolanin’s picture

This is not the right syntax for schema API:

+  db_add_index('oauth2_server_token', 'token', array('token(255)'));
pjcdawkins’s picture

Status: Needs work » Needs review
StatusFileSize
new663 bytes

This is a completely different approach. It should ensure that the library asks Drupal to store only the token ID, not the entire token.

pjcdawkins’s picture

StatusFileSize
new759 bytes

Same as #10 but adds a comment. The automated tests won't work on Drupal.org until we find a way to install the library.

  • pjcdawkins committed 00ac970 on
    Issue #2409125 by pjcdawkins, spdaly, jdiggety, flemeur, pwolanin: Token...
pjcdawkins’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.