hackalive Posted December 29, 2011 Share Posted December 29, 2011 Hi guys, I am using this OAuth library https://github.com/hswong3i I am trying to parse the string to token.php http://localhost/sandbox/token.php?grant_type=authorization_code&client_id=0123456789ab&client_secret=secrettest&code=3b186c90256fc572027a5eb7fb2e51f8&redirect_uri=/ Now this is not working But if I use Poster (FF Plugin) and do this: URL: http://localhost/sandbox/token.php Content Type: application/x-www-form-urlencoded Parameter Body: grant_type=authorization_code&client_id=0123456789ab&client_secret=secrettest&code=3b186c90256fc572027a5eb7fb2e51f8&redirect_uri=/ It works! So why will it not parse form URL? Any help is greatly appreciated. Cheers in advance. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/ Share on other sites More sharing options...
QuickOldCar Posted December 29, 2011 Share Posted December 29, 2011 Well I'm not sure what that code does from https://github.com/hswong3i, but since are in the php forum, here's a way to do it. I tend to favor parse_url() , although are other methods. <?php //$url = "http://localhost/sandbox/token.php?grant_type=authorization_code&client_id=0123456789ab&client_secret=secrettest&code=3b186c90256fc572027a5eb7fb2e51f8&redirect_uri=/"; $url_path = end(explode("/",parse_url($url, PHP_URL_PATH))); echo $url_path."<br />"; $url_query = parse_url($url, PHP_URL_QUERY); echo $url_query."<br />"; if(preg_match("/&/",$url_query)){ $parameters = explode("&",$url_query); } else { $parameters[] = $url_query; } foreach($parameters as $parameter){ $value = explode("=",$parameter); echo "Request: " . $value[0] . " Value: " . $value[1] . "<br />"; } ?> Results would be: token.php grant_type=authorization_code&client_id=0123456789ab&client_secret=secrettest&code=3b186c90256fc572027a5eb7fb2e51f8&redirect_uri=/ Request: grant_type Value: authorization_code Request: client_id Value: 0123456789ab Request: client_secret Value: secrettest Request: code Value: 3b186c90256fc572027a5eb7fb2e51f8 Request: redirect_uri Value: / Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302129 Share on other sites More sharing options...
hackalive Posted December 29, 2011 Author Share Posted December 29, 2011 Sorry, this is the correct code link ... https://github.com/hswong3i/oauth2-php As you can see we are focused on token.php in the PDO folder Also you code is not helpful as it is not parsing the ?grant_type=a.... to the token.php, its merely splitting the URL into segments and returning them in HTML to view. An additional note, when using the FF Plugin, I press POST. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302169 Share on other sites More sharing options...
bspace Posted December 29, 2011 Share Posted December 29, 2011 perhaps you mean "passing" not "parsing" Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302173 Share on other sites More sharing options...
hackalive Posted December 29, 2011 Author Share Posted December 29, 2011 perhaps i do thanks for pointing it out It essentially needs to post that string (I have attached to the URL) to that URL and then do file contents get from that token.php file whcih that sting was submitted to, or at least thats what the FF Plugin simulates. Cheers again. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302200 Share on other sites More sharing options...
Muddy_Funster Posted December 29, 2011 Share Posted December 29, 2011 what do you get if you put this at the top of your token.php page: echo " server method is set to ".$_SERVER['REQUEST_METHOD']; print_r("<br>".$_GET); Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302206 Share on other sites More sharing options...
hackalive Posted December 30, 2011 Author Share Posted December 30, 2011 @Muddy_Funster server method is set to GET<br>Array Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302381 Share on other sites More sharing options...
hackalive Posted December 30, 2011 Author Share Posted December 30, 2011 Please see attached, this is the export I get from the FF Plugin. Window on the right is what I enter and when I press POST the output is the left window. I am now using a seperate file (2.php) with this code (below) to ensure it does the correct POST $postdata = http_build_query( array( 'grant_type' => 'authorization_code', 'client_id' => '0123456789ab', 'client_scret' => 'secrettest', 'code' => '3b186c90256fc572027a5eb7fb2e51f8', 'redirect_uri' => '/sandbox/' ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents('http://localhost/sandbox/token.php', false, $context); echo $result; But I get this error: Warning: file_get_contents(http://localhost/sandbox/token.php) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in D:\public\sandbox\2.php on line 24 Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302402 Share on other sites More sharing options...
hackalive Posted December 30, 2011 Author Share Posted December 30, 2011 Sorry guys I cant upload the file it says this sites upload folder is full. So I put it here http://www.tiikoni.com/tis/view/?id=468176c Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302411 Share on other sites More sharing options...
trq Posted December 30, 2011 Share Posted December 30, 2011 Sorry guys I cant upload the file it says this sites upload folder is full. So I put it here http://www.tiikoni.com/tis/view/?id=468176c Fixed. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302416 Share on other sites More sharing options...
hackalive Posted December 30, 2011 Author Share Posted December 30, 2011 Thanks thorpe Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302427 Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2011 Share Posted December 30, 2011 I'm not getting this, Your server request method is set to get, but you have the following code: ... $opts = array('http' => array( 'method' => 'POST', ... and there is nothing getting passed through the GET global when you move to the next page, even though there are variables in your url......weird Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302470 Share on other sites More sharing options...
hackalive Posted December 30, 2011 Author Share Posted December 30, 2011 @Muddy_Funster The post saying I get GET was from before I made the modifications listed in the next post. The post that mentions 2.php and all post onward are from where I have the code to set POST. Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302510 Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2011 Share Posted December 30, 2011 Post doesn't get variable info from the URL, it is sent from the form directly to the POST superglobal. What way do you want to do things? using POST form variables or or using GET URL variables? Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302513 Share on other sites More sharing options...
hackalive Posted December 30, 2011 Author Share Posted December 30, 2011 Sorry, that last post confused me. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302514 Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2011 Share Posted December 30, 2011 if you send information between pages using method="POST" then you are not using the url, it is sent directly from the HTML form to the $_POST[] global variable. If you are using information from the url to populate variables then you need to use method="GET". $_GET[] 'gets' the variables from the url as the page is loaded. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302545 Share on other sites More sharing options...
hackalive Posted December 30, 2011 Author Share Posted December 30, 2011 i just need to replicate the FF Plugin actions, so if someone can tell me how to do that (see screenshot above) that would be best Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302585 Share on other sites More sharing options...
hackalive Posted January 1, 2012 Author Share Posted January 1, 2012 BUMP I really need and would like to get this sorted Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1302968 Share on other sites More sharing options...
hackalive Posted January 2, 2012 Author Share Posted January 2, 2012 Absolute shameless bump Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1303214 Share on other sites More sharing options...
PaulRyan Posted January 2, 2012 Share Posted January 2, 2012 Try this? <?PHP //### Set the post query $postQuery = array('grant_type'=>'authorization_code', 'client_id'=>'0123456789ab', 'client_secret'=>'secrettest', 'code'=>'3b186c90256fc572027a5eb7fb2e51f8', 'redirect_uri'=>'/sandbox/'); //### Initiate a new cURL $ch = curl_init(); //### Set the options for the cURL request curl_setopt($ch, CURLOPT_URL, 'http://localhost/sandbox/token.php'); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postQuery); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $output = curl_exec($ch); curl_close($ch); //### Echo the output received echo $output; ?> Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1303235 Share on other sites More sharing options...
hackalive Posted January 4, 2012 Author Share Posted January 4, 2012 @PaulRyan, Perfect! Thanks heaps. Also a thanks to all those who made suggestions and helped out. Have a good one. Quote Link to comment https://forums.phpfreaks.com/topic/254000-end-point/#findComment-1303987 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.