hapi icon indicating copy to clipboard operation
hapi copied to clipboard

Secure API example

Open zakkwylde opened this issue 13 years ago • 11 comments

Hi,

Still trying to get across hapi. Looks great.

Would you be able to a a simple example for a secure api example and show how to limit access to various api's that users can call?

I know it's a alot to ask.

Thanks

G.

zakkwylde avatar Jul 14 '13 11:07 zakkwylde

They have some auth examples embedded in API reference http://spumko.github.io/resource/api/#server-auth-name--options-

Examples folder in Github repo https://github.com/spumko/hapi/blob/master/examples/auth.js

Integration tests https://github.com/spumko/hapi/blob/master/test/integration/auth.js

And an external authentication plugin module which has examples too https://github.com/spumko/travelogue

paullang avatar Jul 14 '13 17:07 paullang

Hi,

looking at auth.js in the examples folder. the first curl statement works ok (basic), but the second (hawk) fails. what am I doing wrong.

    console.log('\nHawk request to /hawk:');
    console.log('curl ' + server.info.uri + '/hawk -H \'Authorization: ' + internals.hawkHeader('john', '/hawk', server) + '\'');
    console.log('\nBasic request to /multiple:');

{"code":401,"error":"Unauthorized","message":"Missing authentication"}curl: (6) Could not resolve host: Hawk .. ..

zakkwylde avatar Jul 17 '13 06:07 zakkwylde

Can you paste the actual console of what the example prints and what you typed?

hueniverse avatar Jul 17 '13 07:07 hueniverse

as below (the hawk examples did not work) I cut and pasted as is.

Basic request to /basic: curl http://HAULT024:8000/basic -H "Authorization: Basic am9objpzZWNyZXQ="

Hawk request to /hawk: curl http://HAULT024:8000/hawk -H 'Authorization: Hawk id="john", ts="1374553996", nonce="ldt2qN", mac="RWYfIAbvmRJ10PlUBe076aweMob62e4x3JpyIBGZA/c="'

Basic request to /multiple: curl http://HAULT024:8000/multiple -H "Authorization: Basic am9objpzZWNyZXQ="

Hawk request to /multiple: curl http://HAULT024:8000/multiple -H 'Authorization: Hawk id="john", ts="1374553997", nonce="dWxbhQ", mac="p8C6niP9FBKTNgf0MMka0ZiVvT3CSWbMejrN5yjPi+U="'

On Wed, Jul 17, 2013 at 5:27 PM, Eran Hammer [email protected]:

Can you paste the actual console of what the example prints and what you typed?

— Reply to this email directly or view it on GitHubhttps://github.com/spumko/hapi/issues/964#issuecomment-21096360 .

zakkwylde avatar Jul 23 '13 04:07 zakkwylde

Looks like a problem with the hostname. I'll take a look.

hueniverse avatar Jul 23 '13 05:07 hueniverse

also I changed. http://HAULT024:8000/hawk http://hault024:8000/hawk

to http://127.0.0.1:8000/hawk http://hault024:8000/hawk

this did not work either.

Thanks

On Tue, Jul 23, 2013 at 3:56 PM, Eran Hammer [email protected]:

Looks like a problem with the hostname. I'll take a look.

— Reply to this email directly or view it on GitHubhttps://github.com/spumko/hapi/issues/964#issuecomment-21394681 .

zakkwylde avatar Jul 23 '13 06:07 zakkwylde

Hi Eran,

While I am in contact. What's the best authentication to use with hapi for an api server. hawk - bewit?

On Tue, Jul 23, 2013 at 4:18 PM, Graeme Cox [email protected] wrote:

also I changed. http://HAULT024:8000/hawk http://hault024:8000/hawk

to http://127.0.0.1:8000/hawk http://hault024:8000/hawk

this did not work either.

Thanks

On Tue, Jul 23, 2013 at 3:56 PM, Eran Hammer [email protected]:

Looks like a problem with the hostname. I'll take a look.

— Reply to this email directly or view it on GitHubhttps://github.com/spumko/hapi/issues/964#issuecomment-21394681 .

zakkwylde avatar Jul 23 '13 06:07 zakkwylde

Hi,

Have you had a chance to look into this?

Thanks

Looks like a problem with the hostname. I'll take a look.

On Tue, Jul 23, 2013 at 4:37 PM, Graeme Cox [email protected] wrote:

Hi Eran,

While I am in contact. What's the best authentication to use with hapi for an api server. hawk - bewit?

On Tue, Jul 23, 2013 at 4:18 PM, Graeme Cox [email protected] wrote:

also I changed. http://HAULT024:8000/hawk http://hault024:8000/hawk

to http://127.0.0.1:8000/hawk http://hault024:8000/hawk

this did not work either.

Thanks

On Tue, Jul 23, 2013 at 3:56 PM, Eran Hammer [email protected]:

Looks like a problem with the hostname. I'll take a look.

— Reply to this email directly or view it on GitHubhttps://github.com/spumko/hapi/issues/964#issuecomment-21394681 .

zakkwylde avatar Jul 29 '13 23:07 zakkwylde

Sorry, not yet. Busy with some production issues...

hueniverse avatar Jul 30 '13 17:07 hueniverse

@zakkwylde is this still an issue? What versions of hapi and node are you using.

hueniverse avatar Sep 09 '13 20:09 hueniverse

Please reopen if this still an issue.

hueniverse avatar Oct 02 '13 07:10 hueniverse