Trying to set up a Staging Server - Cannot redeclare class OAuthException


#1

I have an application that lives on http://www.someurl.com. I also have a staging environment setup at http://staging.someurl.com. The problem is coming up in terms of OAuth. When I login in my staging environment, everything flows correctly (logging in on twitter, etc) and then it dumps me off at http://www.someurl.com. When I go back to my staging environment, I am getting the error “Cannot redeclare class OAuthException.” But when I go to the production server (which has the same code), I don’t get any errors. Why does it think the staging server is trying to redeclare this class, but it doesn’t think the production environment is to redeclare it? Something to do with the URL, but what? Any help you can provide is very much appreciated.


#2

Are you using some sort of dynamic language such as PHP?

It sounds like there’s some sort of auth error occurring in your staging environment. This may be a misconfiguration, a server clock out of sync, invalid keys, or something like that. That error is triggering a code path which is probably trying to dynamically include another copy of your OAuth library.

Check your error handling code and your includes. There must be a redundancy somewhere.


#3

Yes I am using PHP. And the pages are literally identical comparing the two servers. Actually its the same server, just different directories. Just not sure why two identical pages would be have different. Probably something to do with what happens behind the scenes on twitter’s end regarding the two different urls…but can’t seem to put my finger quite on it.


#4

No, this is an error on your end. There are two different code paths being executed, one includes an extra copy of your OAuth library.


#5

I don’t understand. The code is dead-on identical. So are you saying the login cookie is storing the path, which is causing a redeclare? If so, wouldn’t that mean something in the application would need to change to account for a different path?


#6

What I mean is that even though the code is the same, the server is executing two different paths through the code, depending on whether you’re on staging or not. The path being executed on staging includes your oauth library more than once, causing the error.

Typically, this kind of thing is caused by an error handler or some sort of other if-then check. If your staging auth flow redirects to production at the end, how are you getting back to staging in order to complete auth?


#7

I see.

The authentication flow is the problem. I go to my staging environment. I login in, but then I end up on the production machine on the Account Page. I then manual type in the URL to the “Account” Page on the staging server, and then am given the re-declaration error.

Does this mean I need to setup a duplicate application that directs me to the Staging environment, instead of the Production environment, to avoid this re-declaration error?


#8

That would be one approach, another would be to make the callback URL dynamic, by passing a custom oauth_callback parameter with the current server’s address when getting a request token.


#9

Interesting. So its the callback URL that basically “welds” the server address with the login cookie. And the way I am doing it now is seeing two different paths with the same class name. It has no idea its the same code, its just preventing me redeclaring a class of the same name. That makes total sense.

Do you know of any sample code of what you mentioned regarding the dynamic url?


#10

This page shows the HTTP requests for obtaining a request token which include passing an oauth_callback parameter:
https://dev.twitter.com/docs/auth/implementing-sign-twitter

If you want PHP examples, it will depend on the library you’re using. Most libraries offer the ability to dynamically generate or customize the oauth_callback parameter.

For example, this tmhOAuth example shows passing oauth_callback as part of the request token flow: https://github.com/themattharris/tmhOAuth/blob/master/examples/oauth_flow.php


#11

Thank you very much for these links. I will dig into them. I am using the tmhOAuth library so will look into it. Thanks!


#12

Hello. I implemented the dynamic call back URL which works great. I did still notice that I was still getting the redeclaration errors so I implemented some code in that file which checks to see if a class has been declared, before redeclaring it (on the production server). This works, however I am wondering why it is still looking at the production server to declare these Oauth classes. I am using this for my Oauth classes: http://oauth.googlecode.com/svn/code/php/OAuth.php
I have checked for any sort of “includes” or paths pointing to it, but nothing. Can you think of anywhere else to look? Something within the Twitter application console?

Thanks so much for your assistance. Almost there.


#13

had this same problem. For some reason, I redirected it back to staging environment and it worked fine. Crazy. I don’t understand why it would matter.


#14

We´re same problem, but in this case with the twitt publication´s. Only just stopped working on June 1.