Issue authenticating to API
Please confirm you have done the following before posting your bug report:
- [ X ] I have enabled debug mode
- [ X ] I have read checked the Common Issues page
Describe the bug
Unable to connect to the API on a fresh install. All attempts result in an {"error":"Unauthorized or unauthenticated."} response from the server. I've attempted with 3 different keys generated from two different users.
The application is set for debug logging but no log entries are appended to laravel.log after the API request is made.
To Reproduce Steps to reproduce the behavior:
- Generate a new api key for a user with 'Super Admin' access
- Attempt to connect to the API as described in the API documentation:
curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <api token>" http://snipe-it/api/v1/hardware
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 44 100 44 0 0 88 0 --:--:-- --:--:-- --:--:-- 88{"error":"Unauthorized or unauthenticated."}
Expected behavior Expect to see the hardware list response data
Server (please complete the following information):
- Snipe-IT Version: 5.0.12
- OS: CentOS 7
- Web Server: httpd-2.4.6-97.el7.centos.x86_64
- PHP Version: php73-2.0-1.el7.remi.x86_64
Desktop (please complete the following information):
- OS: N/A
- Browser: N/A
- Version N/A
Error Messages
- WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error
- If a stacktrace is provided in the error, include that too.
- Any errors that appear in your browser's error console.
- Confirm whether the error is reproducible on the demo: https://snipeitapp.com/demo.
- Include any additional information you can find in
storage/logsand your webserver's logs. - Include the output from
php -m(this should display what modules you have enabled.)
Additional context This is a fresh install. Using the application via the web front end is fine. Only issue is when attempting to connect to the api
👋 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.
Pretty much the same issue for the last few days. Unable to login via API. Tried dozens of times with different accounts and tokens. No result.
"error": "Unauthorized or unauthenticated."
Not sure if this is related. But we're getting an issue right now that is similar.
We create a token it works for about a day then we get an unauthorized error message. Token lifetime should be 40 years.
Same here as well. Always the unauthorized/unauthenticated error message regardless of key generation. I was on an older 5.0.something version and now updated to 5.1.4 and the issue persists. Any help would be great!
@uberbrady you saw this before with 32-bit versions of PHP, right?
Possible duplicate of #9157
The thing I saw was 32-bit versions of PHP and very long-lived API tokens (20-ish years) - where you basically couldn't create new tokens, or the new tokens wouldn't work, because it was doing date-math on dates after the year 2038 if memory serves.
A test you can try is to set API_TOKEN_EXPIRATION_YEAR to 10 (or so), and then issue a new token - then try out that new token.
A permanent fix would be to upgrade to using a 64-bit version of PHP (which is probably a good idea regardless).
I can confirm that this fix does work. Changing the default from 40 down (I changed down to 1) and now it's working! Hopefully will switch to the 64-bit PHP later on, but this works for now. Thanks to you both @snipe & @uberbrady !
Excellent, thanks for the follow up!
We're using 64-bit PHP with the official Docker image and have this same issue.
I'll try changing the default duration of the token to 10 years as suggested.
I'm facing the same issue on our instance.
Version: 5.3.1
PHP: 7.4.3
I already set API_TOKEN_EXPIRATION_YEAR to 10 but the error still exists.
We're using 64-bit PHP with the official Docker image and have this same issue.
I'll try changing the default duration of the token to 10 years as suggested.
Did this work for you?