hackalive Posted April 7, 2012 Share Posted April 7, 2012 Hi guys, I am using this oAuth library https://github.com/elbunce/oauth2-php But more specifically these lines of code: protected function getToken($token, $isRefresh = true) { try { $tableName = $isRefresh ? self::TABLE_REFRESH : self::TABLE_TOKENS; $tokenName = $isRefresh ? 'refresh_token' : 'oauth_token'; $sql = "SELECT $tokenName, client_id, expires, scope, user_id FROM $tableName WHERE token = :token"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':token', $token, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result !== FALSE ? $result : NULL; } catch (PDOException $e) { $this->handleException($e); } } However, this is retuning no value. If I modify the code to be: protected function getToken($token, $isRefresh = true) { return $token; } It returns the $token value, so the $token is definitely being passed to the function. The code should return an associative array: i.e., $token["expires"], $token["client_id"], $token["userd_id"], $token["scope"], etc Also $token should not === NULL. PS. I run a few checks on $tableName = $isRefresh ? self::TABLE_REFRESH : self::TABLE_TOKENS; $tokenName = $isRefresh ? 'refresh_token' : 'oauth_token'; And they are returning the correct values. Which from my thinking narrows it down to: $sql = "SELECT $tokenName, client_id, expires, scope, user_id FROM $tableName WHERE token = :token"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':token', $token, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result !== FALSE ? $result : NULL; Any and all help is greatly appreciated. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Nasir Posted April 7, 2012 Share Posted April 7, 2012 Whats the value of $result ? Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 7, 2012 Author Share Posted April 7, 2012 If i modify the code to return $result; It returns no value still at all. As an added note, PHP is not returning any errors either. Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 7, 2012 Author Share Posted April 7, 2012 If I do return $sql; The output is: SELECT oauth_token, client_id, expires, scope, user_id FROM access_tokens WHERE token = :token Which is all correct I believe. Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 7, 2012 Author Share Posted April 7, 2012 So you guys know what I have tried and maybe can help narrow down the prolem. If I do this (add 'return' to the line in its exiting place): return $stmt->bindParam(':token', $token, PDO::PARAM_STR); It reruns the a value of: 1 However if I was to return the execute() line I again get no value returned. Quote Link to comment Share on other sites More sharing options...
kicken Posted April 7, 2012 Share Posted April 7, 2012 Your code looks ok to me as it is. Your query is probably just returning zero-rows so your ->fetch call is returning false. Run the query manually in mysql to verify (substituting the proper value for your :token placeholder). Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 7, 2012 Author Share Posted April 7, 2012 Ran the Manual SQL query. It found a result. I updated the code to run the SQL query to: [php $sql = "SELECT $tokenName, client_id, expires, scope, user_id FROM $tableName WHERE token = :token"; [/code] If I echo the return it now gives me: Array However if I echo $token["expires"] I get: Notice: Undefined index: expires in .... Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 7, 2012 Author Share Posted April 7, 2012 Managed to get it working now. http://www.phpfreaks.com/forums/index.php?topic=357211.0 (If anyone is game ) Anyone whos after a relatively debugged (thanks to you guys) oAuth library for PHP feel free to PM me Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.