davidfcalle / oauth-php

Automatically exported from code.google.com/p/oauth-php
MIT License
0 stars 0 forks source link

addConsumerRequestToken: column ost_usa_id_ref is hardcoded to value 1 and fails if fk constraints are activated but no user with id 1 exists #112

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Request request token from consumer site with $token = 
OAuthRequester::requestRequestToken($consumer_key, $user_id);
2. On the provider site, call $server->RequestToken

What is the expected output? What do you see instead?
Consumer request token should be added.
Nothing happens on consumer site. Investigating the logs we can see that a 
foreign key is failing at the moment the request token would be saved in the 
oauth_server_token table

[...]
SQL Error in OAuthStoreMySQL: Cannot add or update a child row: a foreign key 
constraint fails (`db`.`oauth_server_token`, CONSTRAINT 
`fk_oauth_server_token_user` FOREIGN KEY (`ost_usa_id_ref`) REFERENCES `user` 
(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE)\n\n\n\t\t\t\tINSERT INTO 
oauth_server_token\n\t\t\t\tSET ost_osr_id_ref\t\t= 
3,\n\t\t\t\t\tost_usa_id_ref\t\t= 1,\n\t\t\t\t\tost_token\t\t\t= 
'067dd1f790e2d56bc16dc881dc2b9fb404de44f72',\n\t\t\t\t\tost_token_secret\t= 
'0b4714d0c0dccecc0120b62deb79220c',\n\t\t\t\t\tost_token_type\t\t= 
'request',\n\t\t\t\t\tost_token_ttl       = DATE_ADD(NOW(), INTERVAL 3600 
SECOND),\n\t\t\t\t\tost_callback_url    = 'oob'\n\t\t\t\tON DUPLICATE KEY 
UPDATE\n\t\t\t\t\tost_osr_id_ref\t\t= 
VALUES(ost_osr_id_ref),\n\t\t\t\t\tost_usa_id_ref\t\t= 
VALUES(ost_usa_id_ref),\n\t\t\t\t\tost_token\t\t\t= 
VALUES(ost_token),\n\t\t\t\t\tost_token_secret\t= 
VALUES(ost_token_secret),\n\t\t\t\t\tost_token_t
[...]

What version of the product are you using? On what operating system?
oauth-php-175, Linux hostname 2.6.35-28-generic #50-Ubuntu SMP Fri Mar 18 
19:00:26 UTC 2011 i686 GNU/Linux (Ubuntu 10.10)

Please provide any additional information below.

Problem can be solved modifying oauth_server_token table definition removing 
NOT NULL from ost_usa_id_ref column and setting the value in 
addConsumerRequestToken to NULL instead of hardcoded 1

[...]
        $this->query('
                INSERT INTO oauth_server_token
                SET ost_osr_id_ref      = %d,
                    ost_usa_id_ref      = NULL,
                    ost_token           = \'%s\',
[...]

Problem can also be solved removing the foreign key.

Best regards,
Eric Janz

Original issue reported on code.google.com by ericj...@gmail.com on 31 May 2011 at 12:57