DAVIDhaker / django-sso

https://pypi.org/project/django-sso/
27 stars 12 forks source link

Install issue #3

Closed kakulukia closed 1 year ago

kakulukia commented 1 year ago

Hi, i just found this project and was trying to integrate it, but im stuck at some level.

First i integrated it with the server. Worked like a charm and also the admin interface looks very clean and easy. One minor issue tho: If the registered service is offline or not working correctly, i cant login to the server because of a connection error.

This should be handled gracefully and still allow me to login even if the service is not running. But this can be handled by deactivating the service in a shell, to get in again and copy the forgotten token. Yes, the docs mention the token is needed somewhere, but it wasnt totally obvious at first try. So for whatever reasons i logged out of the server and created a deadlock. :)

After settings up the client part, i am able to navigate to login and get redirected to the server. But at this step i get a login form no matter if im already logged into the server or not. So i think there is already something wrong at this stage.

Going further, i can see at the client that at some stage a User gets created in the DB, but at this step:

def authorize_from_sso_view(...):
    ...
    if not request.session.session_key or not request.session.get('token', ''):

the token is empty so i get redirected to the start page ('/') instead of getting logged in.

Where should that token come from?

Im still trying to debug that and will have a further look at the server side where it should notice the user already being logged in. And i also will try to use some barebones naked Django test apps for client and server to rule out any changes i made in my project.

Any help appreciated.

kakulukia commented 1 year ago

Also i just noticed if something goes wrong during the first soo try, i get logged out of the server, which is very good security wise, but prevents me from having a second look at the service token in case i get "Application token is'nt exist" on the first try as i got it just now with my barebones Django app instances.

kakulukia commented 1 year ago

There is a really severe error in the services admin, which will probably prevent everyone from having successful first try experience.

Saving the service generates another token for the service.

Steps to reproduce: . Add a service . copy the token right away . try to not produce an error with the url, as this will also regenerate another token . hit save and continue editing . watch the token change

So copying the token right away for use in the client will get you into the above deadlock, because it will be the wrong token.

kakulukia commented 1 year ago

What looks strange: get_success_url will redirect to f'{auth_request.service.base_url}/sso/accept/' without any token being added.

It looks like no data is transferred here. But i may be missing a detail.

I have uploaded the sample projects here (server - https://github.com/kakulukia/test_server ) and here (client - https://github.com/kakulukia/test_client )

The user registered at the server is "demo" with password "1234". Start the server as usual with manage.py runserver and start the client with manage.py runserver localhost:7777 to match the registered service in the sqliteDB.

kakulukia commented 1 year ago

calling server/login/ is somehow deleting the session cookie, thus the needed relogin even if i was logged in before - thats all i found so far

DAVIDhaker commented 1 year ago

Hello @kakulukia! Great thanks for too detailed review. Now i started to work on problems you described. Little bit later i will post answer here!

kakulukia commented 1 year ago

Thank you, @DAVIDhaker !

kakulukia commented 1 year ago

Hey @DAVIDhaker is there any progress? Were the test apps of any use?

DAVIDhaker commented 1 year ago

Hello. Work in process. You can see result at several days.

DAVIDhaker commented 1 year ago

@kakulukia, you can read the CHANGELOG.md.

kakulukia commented 1 year ago

Thx, I will test that asap and report back!

kakulukia commented 1 year ago

Loggin in to server if sso-clients are offline: works ✔︎ Token keeps changing after save: not happening any more ✔︎ Login attempt at the client: still not working the way i tried before .. BUT your addition to the readme also solved this issue ✔︎

Thank you very much!

DAVIDhaker commented 1 year ago

Thanks so much for you too! Your detailed issue helped to improve this library!