mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-17 05:47:58 +08:00
* move local_server -> backend/server server-> backend/czi_hosted, pull common code into backend/common update imports, tests and make commands
40 lines
1014 B
Python
40 lines
1014 B
Python
from backend.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, app_config):
|
|
super().__init__()
|
|
|
|
def is_valid_authentication_type(self):
|
|
return True
|
|
|
|
def complete_setup(self, app):
|
|
pass
|
|
|
|
def is_user_authenticated(self):
|
|
# always authenticated
|
|
return True
|
|
|
|
def get_user_id(self):
|
|
if self.CXGUID not in session:
|
|
session[self.CXGUID] = uuid4().hex
|
|
session.permanent = True
|
|
return session[self.CXGUID]
|
|
|
|
def get_user_name(self):
|
|
return "anonymous"
|
|
|
|
def get_user_email(self):
|
|
return None
|
|
|
|
|
|
AuthTypeFactory.register("session", AuthTypeSession)
|