API token authentication

2,765 views
Skip to first unread message

Luis Bueno

unread,
May 17, 2017, 3:48:39 PM5/17/17
to NetBox

Hello!

I'm currently using Netbox 2.0.2. When I try to use the API to create a object I get the message "Authentication credentials were not provided.".

Is the authorization header wrong or I'm dealing with a bug?

That's the test request I'm running:

curl -X POST -H "Authorization: Token b275f46c755800c72ecf264a3befe2a01cb9993e" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://netbox.xxxxxx.com/api/dcim/sites/ --data '{"name": "My New Site", "slug": "my-new-site"}'
{
    "detail": "Authentication credentials were not provided."
}



Regards.
Luis bueno

Jeremy Stretch

unread,
May 17, 2017, 4:16:16 PM5/17/17
to Luis Bueno, NetBox
Your request appears to be correct and should result in a successful response, assuming the token is valid. It's possible that the front end HTTP server isn't passing the authorization header to the WSGI service. What happens when you pass the same request to the development server directly? (./manage.py runserver will start the development server locally.)

Jeremy

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/e572ac2d-f09f-46ce-9b1f-2698ba850d99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Bueno

unread,
May 17, 2017, 4:41:39 PM5/17/17
to NetBox

Jeremy, that's right. Apache wasn't passing the authorization header.

After inserting "WSGIPassAuthorization On" in wsgi mod configuration file, the API started to accept the token.

Regards.
Luis Bueno


On Wednesday, May 17, 2017 at 5:16:16 PM UTC-3, Jeremy Stretch wrote:
Your request appears to be correct and should result in a successful response, assuming the token is valid. It's possible that the front end HTTP server isn't passing the authorization header to the WSGI service. What happens when you pass the same request to the development server directly? (./manage.py runserver will start the development server locally.)

Jeremy
On Wed, May 17, 2017 at 3:48 PM, Luis Bueno <luise...@gmail.com> wrote:

Hello!

I'm currently using Netbox 2.0.2. When I try to use the API to create a object I get the message "Authentication credentials were not provided.".

Is the authorization header wrong or I'm dealing with a bug?

That's the test request I'm running:

curl -X POST -H "Authorization: Token b275f46c755800c72ecf264a3befe2a01cb9993e" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://netbox.xxxxxx.com/api/dcim/sites/ --data '{"name": "My New Site", "slug": "my-new-site"}'
{
    "detail": "Authentication credentials were not provided."
}



Regards.
Luis bueno

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To post to this group, send email to netbox-...@googlegroups.com.

Jeremy Stretch

unread,
May 17, 2017, 5:20:22 PM5/17/17
to Luis Bueno, NetBox
Interesting. I'll add that bit to the installation docs. Thanks for following up!

To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/15ad40cb-7cab-4c2f-8cf6-e88eb76ccebc%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages