Accessing API on Windows
Please confirm you have done the following before posting your bug report:
- [ Yes] I have enabled debug mode
- [ Yes] I have read checked the Common Issues page
Describe the bug Accessing API from Postman (or any other way). We get an error which says:
"error": "Unauthorized or unauthenticated."
To Reproduce Steps to reproduce the behavior:
- Install 5.1 on Windows
- Login as admin and create an API Key
- Use the Key in Postman as per documentation
- See error
Expected behavior Should return the list of Users Screenshots If applicable, add screenshots to help explain your problem.
Server (please complete the following information):
- Snipe-IT Version : Version v5.1.1 - build 5811 (master)
- OS: Windows Server 2019
- Web Server: IIS
- PHP Version : 7.4
Desktop (please complete the following information):
- OS: Windows 10
- Browser : Chrome
- Version NA
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Error Messages -NA
Additional context
- Is this a fresh install or an upgrade? - Fresh
- What OS and web server you're running Snipe-IT on - Windows 2019/ 10
- What method you used to install Snipe-IT: Git
- Include what you've done so far in the installation, and if you got any error messages along the way.- No - System in active use
- Indicate whether or not you've manually edited any data directly in the database - NO
Add any other context about the problem here.
Please do not post an issue without answering the related questions above. If you have opened a different issue and already answered these questions, answer them again, once for every ticket. It will be next to impossible for us to help you.
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
Please post your curl request. Usually when we see this, it's because you're missing a header in your Postman or cURL request.
curl --location --request GET 'https://snipeit.smglegal.co.uk/api/v1/users'
--header 'Authorization: Bearer fake_long_bearer_token_string'
--header 'Content-Type: application/json'
--header 'Accept: application/json'
--header 'Cookie: snipeit_session=ZrhHNNSCHfraed97wH8iRUMvvtfE57bafJlGJ87U'
HI @snipe - Thanks for the quick response! Please see my request above copied from Postman. I have followed the tutorial. The software itself works flawlessly. Its just the APIs which are not accessible.
Hi, We are also getting the same issue.
curl --location --request GET 'http://192.168.29.120:9060/api/v1/hardware' \
--header 'Authorization: Bearer extremely_long_bearer_token_string' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Cookie: snipeit_session=45XDbfaDF1URtM7VQrXhaahn1ixZdOEdwz7nnlhM'
"error": "Unauthorized or unauthenticated."
First off - please don't post live Bearer tokens - I edited those down for both of you folks, hope you don't mind.
My best guess as to what's going on here is that you're confusing the Auth system by sending both an Authorization header and a Cookie with a snipeit_session in it. If you look at our API docs here: https://snipe-it.readme.io/reference#hardware-list the sample code doesn't have the cookie part in it, just the Authorization header. The Accept header certainly isn't going to hurt you (and is generally good practice), but since GET requests have no body, the Content-Type header isn't going to do you any good.
Snipe-IT DocumentationSnipe-IT is a free, open source IT asset management system. Features include management of assets, users, licenses, accessories, consumables and components, as well as two-factor authentication, LDAP/AD syncing, and asset acceptance confirmation.
To the folks having issues here, can you cURL our our develop demo server? (You don't need to share the results with us, it's just demo data, but I'm curious to see if it's reproducible there.)
curl --request GET \
--url 'https://develop.snipeitapp.com/api/v1/hardware' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImVmMGVhY2Y4MjAyYzgwZWI2M2JkNmIwZDc0OGYwY2FkYzU2Y2ZlMzgyNzY4ODY0N2EwNmU4ZTBlNmYwZDgwODNjZmMyMzI2YWYyYTZlMTFkIn0.eyJhdWQiOiIxIiwianRpIjoiZWYwZWFjZjgyMDJjODBlYjYzYmQ2YjBkNzQ4ZjBjYWRjNTZjZmUzODI3Njg4NjQ3YTA2ZThlMGU2ZjBkODA4M2NmYzIzMjZhZjJhNmUxMWQiLCJpYXQiOjE0OTMzMzI2MjgsIm5iZiI6MTQ5MzMzMjYyOCwiZXhwIjoxODA4ODY1NDI4LCJzdWIiOiIyIiwic2NvcGVzIjpbXX0.NU7ZRIt-d4b0o8uv9ipo1vSWcg1svbmPp47kHErafm9iuK4FjygKd2_4Hp73HKAmjiYcEn3r39pwNh2t9BMFnTXv0KeDGC8zfZ9z7OJN_a59LPoarWBFzCsYETyAm-CeeFnfdj9Cr0ZeGOnnaPuWPYxicwKFeqJI4Hn8nCymcamDGE0u4WOO95ihGOAen4_fqpj-kkBDsvsGhB-cQxeuKdlbvO1yOsKmgQv-kQuxiFMn1zgU7P02mC6XXrbw6jTm7JOaBSbvqSwNtsrSKZkim1jxLsQ4dm36lFmeMkU6hZvNSUnxg8JwbmoxQ_3tZlG3IJh3Sc9ZUi-AEAQ4bbGzi_xNS9fenIdzLDaSiv_esYyNOYXqOuSBk8Yr-720N9OcVjGLnPrV3RtmPisV1aLFgKWLImtlyQgUq3d5LA3QXz8Q_8isvO9Am1u8ri2plbHGJLJ6GRW_mYcBEYMwUozaeXTUe_FUSSO8gpGtO9Hpa5SbERY272_tojyVXpYPaPdUYYmS9CP332jBNESPT8wGwpOM-iddeVo_n82w3dHmDEdp1Brbs3_vKk0AcgvDLsAbd4dZZO-UqddVx6SDb3HLw1Pmw1wGGYHA6w8wWQAiS9kg2xMcz5i75HOULaN3miqYvcPCvHpI2CBfuvdplI8QNm_XzFPmoQRu_5kR8knzla4'
(Brady is right to suggest never posting bearer tokens in public, but this one is already public in our API docs)
Thanks @uberbrady for editing my post.
@snipe - I have tried accessing the demo site. See my output below. I get exactly the same from my internal site (login):
<title>Redirecting to https://develop.snipeitapp.com/login</title>
</head>
<body>
Redirecting to <a href="https://develop.snipeitapp.com/login">https://develop.snipeitapp.com/login</a>.
</body>
Hi,
It works properly with demo server but when deployed locally it is giving this error. Pls check API code. WAMP installation locally API test throws unauthorised error. We tried all options but there some issue with latest release API code.
Regards,
On Sat, 20 Feb 2021, 10:09 pm snipe, [email protected] wrote:
@uberbrady https://github.com/uberbrady You have to send both content-type and accept headers for Passport to work properly. (I know, it's dumb.)
To the folks having issues here, can you cURL our our develop demo server? See the API docs Brady just linked to - if you can use the "Try it" button and then copy the curl command it shows you in the right-side panel, that would be helpful. (You don't need to share the results with us, it's just demo data, but I'm curious to see if it's reproducible there.)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/snipe/snipe-it/issues/9157#issuecomment-782711992, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAUEC3I56BF2RFIQZAMSL3S77QTHANCNFSM4X2FL4WQ .
@infotronicx We have not made any changes to the API's authorization since v5. If it works with the demo server, then it works. This seems more environmental to me, as the code you deploy locally is the exact same code we host on the demo.
Can you both run the upgrade.php script and show me the output?
@wq949966 - that's... interesting. Possible you have a firewall or something running that might be stripping out headers?
Can you please eloborate "unauthenticated or unauthorized" error reasons ? and points where we can check to resolve the issue.
On Sat, 20 Feb 2021, 11:42 pm snipe, [email protected] wrote:
@infotronicx https://github.com/infotronicx We have not made any changes to the API's authorization since v5. If it works with the demo server, then it works. This seems more environmental to me, as the code you deploy locally is the exact same code we host on the demo.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/snipe/snipe-it/issues/9157#issuecomment-782726037, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAUEC3GISA4DKUA7PDZFTDS773R3ANCNFSM4X2FL4WQ .
Sure will share with you soon.
On Sat, 20 Feb 2021, 11:44 pm snipe, [email protected] wrote:
Can you both run the upgrade.php script and show me the output?
@wq949966 https://github.com/wq949966 - that's... interesting. Possible you have a firewall or something running that might be stripping out headers?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/snipe/snipe-it/issues/9157#issuecomment-782726377, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAUEC7UUGTUDWIBYDDT4C3S7732HANCNFSM4X2FL4WQ .
@infotronicx also please try generating a new token and trying with that. If you run into any issues while generating, please share them. I'm having to do a lot of guesswork here.
Thank @snipe - I will try on the server itself (removing firewall) to avoid further wasting your time! Its a fantastic system. Thank you!
@wq949966 Or even try at home, or somewhere that's not on your usual network maybe? Just trying to rule some stuff out here. That redirect that you're seeing typically only happens when you're not sending the JSON headers. The app thinks it's a web (vs API) request, so it redirects you to a login.
Hi @snipe - I now have the same result as @infotronicx -
- I can get the API result from Snipe-It demo API
- I have "Unauthorized or unauthenticated." when trying exactly the same against my internal site
I am using postman now but removed the cookies (turning off CookieJar). Removing the cookie helped get the result from the Demo site. But no luck with internal setup :(
@wq949966 thanks very much for that additional info. I can't reproduce this anywhere, but at least the behavior is consistent between the two of you, so that's kinda something.
Can you do a git pull and then a php update.php and show me the output? That script (in addition to updating your version) also tries to check for any missing PHP extensions that previous versions would have glossed over and permitted.
Hi @snipe - I did an update just before I saw your post!
I am trying against version - Version v5.1.1 - build 5811 (master).
@infotronicx do your stats match the same at @wq949966? Both windows servers, etc?
I'd love to see the output of a php -m to show me what modules your PHP is compiled with (or has enabled).
The only other time we've seen this is when there are missing modules/libraries. We don't have a great way to check for this. and Laravel (or Snipe-IT maybe) fail very hard at explaining that that's why it's failing, because it's breaking so far up in the stack, the error logging system in Laravel doesn't even know how to handle it.
The reason we added the modules check in the upgrade.php is specifically to address missing libraries that can cause this issue. The upgrade script checks for PHP extensions/libs that we KNOW the system will break without.
If it's libraries, we usually see the symptoms as the listing tables in the web GUI not loading, but I'm not ruling it out.