MCPcopy Index your code
hub / github.com/python-websockets/websockets / cookie_auth

Function cookie_auth

experiments/authentication/app.py:136–159  ·  view source on GitHub ↗

Authenticate user from token in cookie.

(connection, request)

Source from the content-addressed store, hash-verified

134
135
136async def cookie_auth(connection, request):
137 """Authenticate user from token in cookie."""
138 if "Upgrade" not in request.headers:
139 template = pathlib.Path(__file__).with_name(request.path[1:])
140 body = template.read_bytes()
141 headers = Headers(
142 {
143 "Date": email.utils.formatdate(usegmt=True),
144 "Connection": "close",
145 "Content-Length": str(len(body)),
146 "Content-Type": CONTENT_TYPES[template.suffix],
147 }
148 )
149 return Response(200, "OK", headers, body)
150
151 token = get_cookie(request.headers.get("Cookie", ""), "token")
152 if token is None:
153 return connection.respond(http.HTTPStatus.UNAUTHORIZED, "Missing token\n")
154
155 user = get_user(token)
156 if user is None:
157 return connection.respond(http.HTTPStatus.UNAUTHORIZED, "Invalid token\n")
158
159 connection.username = user
160
161
162def check_credentials(username, password):

Callers

nothing calls this directly

Calls 6

HeadersClass · 0.90
ResponseClass · 0.90
get_cookieFunction · 0.85
get_userFunction · 0.85
getMethod · 0.45
respondMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…