I try to build OAuth authentication in the FlickrAPI module using this code sample: https://gist.github.com/1065774

After authenticating (all seems to work) I get the following PHP notice:

Notice: Use of undefined constant OAUTH_COMMON_TOKEN_TYPE_REQUEST - assumed 'OAUTH_COMMON_TOKEN_TYPE_REQUEST' in DrupalDatabaseCache->prepareItem() (line 428 of /includes/cache.inc).

Any idea what could cause this and how I can solve it? Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BarisW’s picture

And I get this message also:

Notice: Use of undefined constant OAUTH_COMMON_TOKEN_TYPE_REQUEST - assumed 'OAUTH_COMMON_TOKEN_TYPE_REQUEST' in variable_initialize() (line 943 of /includes/bootstrap.inc).

Any thoughts?

BarisW’s picture

I debugged a bit more and found out that it might be caused by the variables declaration in class DrupalOAuthToken:

<?php
public $type = OAUTH_COMMON_TOKEN_TYPE_REQUEST;

?>

if I change this to

<?php
public $type = 0;
?>

All works fine. Can a static be used like this?

BarisW’s picture

Category: support » bug

What started as a support request actually is a bug report.

BarisW’s picture

Steps to reproduce:

- Install FlickrAPI 7.x-1.3
- Go to admin/config/media/flickrapi, fill in Flickr keys and click Authenticate. If you don't have a key and secret contact me and I will send you mine.
- Authenticate to Flickr using OAuth (happens when you save the admin form).

You'll see the notice.

I spoke to juampy on IRC and this was what he said:

juampy: it seems that the constant is not defined at that point, hence the error
juampy: I will have to look the loading order to see if that constant is actually needed and if it is declared/included at the right time

All help here is welcome!

juampynr’s picture

Issue tags: +DrupalWTF

This is a weird one. Basically, some OAuth classes are getting registered at cache_bootstrap table under lookup_cache cid. These classes are being loaded before oauth_common.module, hence the error.

I need to discover at what point does this happens and how to avoid it. For that, I will trace a full OAuth authentication process to see what is going on on each step.

Here is an example of my cache_bootstrap table after authenticating. See how these classes got registered. These classes are loaded very early in the bootstrap process.

    mysql> select data from cache_bootstrap where cid = 'lookup_cache';
    ...
    a:7:{s:30:"cDrupalDefaultEntityController";s:19:"includes/entity.inc";s:18:"cDrupalOAuthClient";s:62:"sites/all/modules/contrib/oauth/includes/DrupalOAuthClient.inc";s:12:"cDrupalQueue";s:31:"modules/system/system.queue.inc";s:17:"cDrupalOAuthToken";s:61:"sites/all/modules/contrib/oauth/includes/DrupalOAuthToken.inc";s:11:"cOAuthToken";s:45:"sites/all/modules/contrib/oauth/lib/OAuth.php";s:20:"cDrupalOAuthConsumer";s:64:"sites/all/modules/contrib/oauth/includes/DrupalOAuthConsumer.inc";s:20:"cSelectQueryExtender";s:28:"includes/database/select.inc";}
BarisW’s picture

For that, I will trace a full OAuth authentication process to see what is going on on each step.

Did you happen to do this yet? It really is an annoying issue, as all sites that rely on the FlickrAPi module (and submodules like FlickrGallery) will see this error/notice once they use the OAuth authentication.

Is there anything I can do in my module to work around this?

juampynr’s picture

I worked on it yesterday and I am not certain of what is going on yet. I was actually reading at how Flickrapi module creates the request token. It seems that info about class DrupalOAuthClient is saved in lookup_cache at drupal_goto() (which saves the user session to database). Twitter module, for example, uses OAuth as well but does not have this problem.

I will work on this a little bit more and hopefully find a fix in OAuth or a patch for Flickrapi.

juampynr’s picture

Project: OAuth 1.0 » Flickr API
Version: 7.x-3.x-dev » 7.x-1.x-dev
Status: Active » Needs review
FileSize
5.09 KB

Moved to Flickrapi module.

The problem comes because the full DrupalOAuthToken object returned from Flickr was being saved using variable_set(). Then drupal_goto() provokes that saved variables get stored at cache_bootstrap table, which finally raises an error for every following page because when this variable is loaded, the class DrupalOAuthToken has not being loaded yet.

I have removed this object from being saved an created a private callback to check if a Flickr account has been authenticated instead.

Please review the suggested patch and consider Git Attribution.

BarisW’s picture

Status: Needs review » Fixed

Awesome Juan! Thanks a lot for the research and the patch.
Committed, with git attribution (of course).

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