codemation / easyauth

Create a centralized Authentication and Authorization token server. Easily secure FastAPI endpoints based on Users, Groups, Roles or Permissions with very little database usage.
https://easyauth.readthedocs.io/en/latest/
MIT License
553 stars 52 forks source link

"401 Unauthorized" when logging to admin account #76

Closed pedrocavadas closed 1 year ago

pedrocavadas commented 1 year ago

I followed all instructions regarding installation and starting an EasyAuth server, but when trying to log in to "/admin" with the "admin" account that is automatically created when launching the server for the first time, I get error "401 Unauthorized". Any idea of what can be happening?

codemation commented 1 year ago

@pedrocavadas - the default admin password should be output in the logs the first time the user is created, generally first runtime. If you do not have access to the logs, the best case is to drop the tables / database & start again.

pedrocavadas commented 1 year ago

That's the issue, when using username "admin" with this generated password, I get the "401 Unauthorized" error, and the log in page doesn't redirect me anywhere.

codemation commented 1 year ago

Do you see the same result from the /docs login?

pedrocavadas commented 1 year ago

From there, it works. I used the username "admin" and the generated password on the "Authorize" button, and tried the /auth/users method, for example.

image image

There it is, created successfully.

codemation commented 1 year ago

Not sure if you have the order that reproduces this from the GUI. My theory is that you are directly browsing to /login, which prompts login and creates the cookie, but does not redirect because there is no ref to redirect to. If you first browsed to /admin/users for instance without being logged in, you would be redirected to /login, which after successful should redirect you back to /admin/users.

If this assumption is not correct, please list the exact steps to reproduce and I will look deeper into this.

pedrocavadas commented 1 year ago

Well, I tried three different endpoints: :/admin, :/admin/users and :/login. On these three tries, I got error "401 Unauthorized", and the GUI didn't redirect me anywhere, staying on the login page.

Steps to reproduce:

  1. Start server via command-line: "uvicorn --host 0.0.0.0 --port test_server:server"
  2. Get the default admin password outputted in the logs
  3. Go to :/admin
  4. Type username "admin" and the password from step 2
  5. Click "Login"
  6. My issue happens
codemation commented 1 year ago

Looks like a new issue with set cookie not working. I reproduced locally as well in a new env, will fix ASAP.

codemation commented 1 year ago

This should be fixed in latest release. https://github.com/codemation/easyauth/releases/tag/1.0.27

Let me know if you run into anything new. Thanks for reporting.

pedrocavadas commented 1 year ago

It works! Thank you so much.

singlautsav commented 1 year ago

INFO: 127.0.0.1:64085 - "GET /admin/ HTTP/1.1" 401 Unauthorized INFO: 127.0.0.1:64103 - "GET /admin/ HTTP/1.1" 401 Unauthorized INFO: 127.0.0.1:64103 - "GET /admin/ HTTP/1.1" 401 Unauthorized INFO: 127.0.0.1:64103 - "GET /admin/ HTTP/1.1" 401 Unauthorized INFO: 127.0.0.1:64103 - "GET /admin/ HTTP/1.1" 401 Unauthorized INFO: 127.0.0.1:64103 - "GET /login HTTP/1.1" 200 OK INFO: 127.0.0.1:64103 - "POST /login HTTP/1.1" 302 Found 07-23 23:30 EasyRpc-server /ws/manager WARNING global_store_update - update - tokens - c91ae036-03af-4562-89e8-cb635bb30a17 INFO: 127.0.0.1:64103 - "GET /admin/ HTTP/1.1" 401 Unauthorized

Getting the same issue where I am unable to login on the frontend with the admin/password generated. While I can do the same on the docs pages.

codemation commented 1 year ago

@singlautsav - it would help if you create a new issue. Ideally with steps to reproduce the problem and a snapshot of your environment i.e pip freeze & basic code example that you observe the issue.

singlautsav commented 1 year ago

@codemation raised as new issue https://github.com/codemation/easyauth/issues/105