Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to open it on Browser? #20

Open
Abhinav1217 opened this issue Jul 9, 2015 · 8 comments
Open

How to open it on Browser? #20

Abhinav1217 opened this issue Jul 9, 2015 · 8 comments

Comments

@Abhinav1217
Copy link

Hi, I am noob in this. I am learning to write secure api-centric application and found your blog post and this repo. I Downloaded it and am trying it since yesterday. I used your nginx file. I am able to run it via php client-connect.php and getting responce. But if i try to use my browser (via nginx or via php inbuilt server) I am getting indexPage doesn't exist. on browser. How do I run it on browser.

@overbid
Copy link

overbid commented Jul 9, 2015

You could replace your nginx config file with nginx-virtual-host-php-fpm.conf. And restart.

@Abhinav1217
Copy link
Author

Did that. I mentioned that I am using your config file. I initially used the url l.papi . Then tried using api.example.com, adding it to the /etc/hosts file. I am getting same error with php -S server also. I am getting response via terminal using your client-connect.php . but not via browser pointing to index file in public folder.

@jeteokeeffe
Copy link
Owner

Can post both the php -S command with output and your client-connect.php command with output.

@jeteokeeffe
Copy link
Owner

You won't be able to see a successful pong request because the necessary http headers won't be sent. That's why need need to use the client app. 
You can test that php is running by putting http://localhost:8000 in your browser

 On Thursday, July 9, 2015 10:58 PM, Abhinav Kulshreshtha <[email protected]> wrote:

Did that. I mentioned that I am using your config file. I initially used the url l.papi . Then tried using api.example.com, adding it to the /etc/hosts file. I am getting same error with php -S server also. —
Reply to this email directly or view it on GitHub.

@Abhinav1217
Copy link
Author

Output from php -S

[Abhinav@abhinav-fed22 public] $ php -S localhost:8000 ../.htrouter.php
PHP 5.6.10 Development Server started at Fri Jul 10 09:01:44 2015
Listening on http://localhost:8000
Document root is /var/www/hmac/public
Press Ctrl-C to quit.
[Fri Jul 10 09:01:54 2015] 127.0.0.1:43440 [404]: /
[Fri Jul 10 09:01:54 2015] 127.0.0.1:43441 [404]: /favicon.ico - No such file or directory
[Fri Jul 10 09:01:59 2015] 127.0.0.1:43442 [404]: /
[Fri Jul 10 09:02:00 2015] 127.0.0.1:43443 [404]: /
[Fri Jul 10 09:03:11 2015] 127.0.0.1:43446 [200]: /ping

404 s are from browser pointing to localhost:8000. last line with [200] is from console.

Output from console

[Abhinav@abhinav-fed22 hmac] $ php client-connect.php 

Request: 
POST /ping HTTP/1.1
Host: localhost:8000
Accept: */*
API_ID: 1
API_TIME: 1436499190
API_HASH: ca6fb67add4409ea244a59af2e2b85483b79c0b49cf773c037dd8c6609c13fea
Content-Length: 142
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------90550a8901f809c9


Response:
HTTP/1.1 200 OK
Host: localhost:8000
Connection: close
X-Powered-By: PHP/5.6.10
Content-type: text/html; charset=UTF-8

indexpong

Output on browser is indexPage doesn't exist.

@jeteokeeffe
Copy link
Owner

The client is connecting and printing out the correct information. Everything is successful.

The reason the browser is failing is because you're not providing the http headers (API_ID: 1
API_TIME: 1436499190
API_HASH: ca6fb67add4409ea244a59af2e2b85483b79c0b49cf773c037dd8c6609c13fea). This project isn't just a restful api, it has authentication through http headers to verify who the user is.

Read this about what hmac is and used for
http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/

@jeteokeeffe
Copy link
Owner

if you just want a restful api, comment out line 68 in https://github.com/jeteokeeffe/php-hmac-rest-api/blob/master/public/index.php. I won't check the http headers

@Abhinav1217
Copy link
Author

I commented the line 68. Still getting indexPage not found. On both localhost:8000 and localhost:8000/ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants