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

API error "Unauthorized or unauthenticated." #10351

Closed
2 tasks done
Isotop7 opened this issue Nov 23, 2021 · 5 comments
Closed
2 tasks done

API error "Unauthorized or unauthenticated." #10351

Isotop7 opened this issue Nov 23, 2021 · 5 comments

Comments

@Isotop7
Copy link

Isotop7 commented Nov 23, 2021

Debug mode

Describe the bug

I'm trying to query the API of our Snipe-IT instance for several days now but I cant get it to work.
My user has admin permissions and I created a token.
When I try to query the API via curl or powershell, I always get {"error":"Unauthorized or unauthenticated."}.

I already decreased to API lifetime to 2 years as mentioned in other posts. I also get no errors in the php or apache log.

Reproduction steps

  1. Create a user with admin permissions
  2. Create a token
  3. Try to query api endpoint

Expected behavior

Get returned values of API call

Screenshots

No response

Snipe-IT Version

5.3.1

Operating System

Ubuntu Server 20.04

Web Server

Apache

PHP Version

7.4.3

Operating System

Windows 11

Browser

No response

Version

No response

Device

No response

Operating System

No response

Browser

No response

Version

No response

Error messages

$ php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

Additional context

No response

@welcome
Copy link

welcome bot commented Nov 23, 2021

👋 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.

@xam-ps
Copy link

xam-ps commented Dec 2, 2021

Did you try to get the api working with postman as described here?
https://snipe-it.readme.io/reference/testing-in-postman

Snipe-IT Documentation
Snipe-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.

@snipe
Copy link
Owner

snipe commented Dec 2, 2021

Please post the curl command

@MascHman
Copy link

Hey, I've found a solution which to my knowledge is not mentioned in any thread:

I had the same Issues, then upgraded to latest release, merged all changes from .env.example to my (3 years old) .env file and lowered the API_TOKEN_EXPIRATION_YEARS . Still nothing. After checking all dependencies there was only one thing left: The Apache Config. It seems I was preventing the loading of internal .htaccess file by using the alternate apache config provided in the install docs [https://snipe-it.readme.io/docs/linuxosx].

So going back to the default apache config was my fix:

<VirtualHost *:80>
    <Directory /var/www/html/public>
        Allow From All
        AllowOverride All
        Options -Indexes
    </Directory>

    DocumentRoot /var/www/html/public
    ServerName www.yourserver.com
    # Other directives here
</VirtualHost>

@Isotop7
Copy link
Author

Isotop7 commented Dec 23, 2021

Hey, I've found a solution which to my knowledge is not mentioned in any thread:

I had the same Issues, then upgraded to latest release, merged all changes from .env.example to my (3 years old) .env file and lowered the API_TOKEN_EXPIRATION_YEARS . Still nothing. After checking all dependencies there was only one thing left: The Apache Config. It seems I was preventing the loading of internal .htaccess file by using the alternate apache config provided in the install docs [https://snipe-it.readme.io/docs/linuxosx].

So going back to the default apache config was my fix:

<VirtualHost *:80>
    <Directory /var/www/html/public>
        Allow From All
        AllowOverride All
        Options -Indexes
    </Directory>

    DocumentRoot /var/www/html/public
    ServerName www.yourserver.com
    # Other directives here
</VirtualHost>

Thank you! That really worked. Updating AllowOverride None to AllowOverride All seems to fix the API errors.

@Isotop7 Isotop7 closed this as completed Jan 5, 2022
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

4 participants