mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-16 21:37:59 +08:00
* Add basic authentication in the server A pattern for creating authentication methods is introduced, with three authentication types defined: none - no authentication session - like the current session based auth used for user annotations test - used to test the login/logout process end to end The config endpoint now returns informations about the authentication, like if the user is authenticated and their username. The redirect uri's for login and logout are also returned if the authentication type requires login This is the first a several PRs for authentication. *. Update server tests to avoid hardcoded ports test_api and test_nan_rest now use a common function for starting a test server, than will initially choose a random port.
37 lines
917 B
Python
37 lines
917 B
Python
from server.auth.auth import AuthTypeBase, AuthTypeFactory
|
|
from flask import session
|
|
from uuid import uuid4
|
|
|
|
|
|
class AuthTypeSession(AuthTypeBase):
|
|
"""Session based authentication. The user is always logged. The user id is a random number
|
|
associated with the session. This is a good choice for desktop servers."""
|
|
|
|
# key in the session token for userid
|
|
CXGUID = "cxguid"
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def is_valid(self):
|
|
return True
|
|
|
|
def set_params(self, params):
|
|
return
|
|
|
|
def is_authenticated(self):
|
|
# always authenticated
|
|
return True
|
|
|
|
def get_userid(self):
|
|
if self.CXGUID not in session:
|
|
session[self.CXGUID] = uuid4().hex
|
|
session.permanent = True
|
|
return session[self.CXGUID]
|
|
|
|
def get_username(self):
|
|
return "anonymous"
|
|
|
|
|
|
AuthTypeFactory.register("session", AuthTypeSession)
|