@@ -251,9 +251,28 @@ def identity_provider(self):
251
251
)
252
252
from jupyter_server .auth import IdentityProvider
253
253
254
- # no identity provider set, load default
254
+ non_alphanum = re .compile (r"[^A-Za-z0-9]" )
255
+ default_cookie_name = non_alphanum .sub ("-" , f"username-{ self .request .host } " )
256
+
257
+ # If there is no identity provider set, load the default. If using
258
+ # a classic notebook server, adding extensions that inherit
259
+ # from JupyterHandler will use a mix of new+old authentication log.
260
+ # Here, we construct an identity provider that works side-by-side
261
+ # and consistently with the old way that we handled auth in
262
+ # the classic server.
255
263
self .settings ["identity_provider" ] = IdentityProvider (
256
- config = self .settings .get ("config" , None )
264
+ config = self .settings .get ("config" , None ),
265
+ # For backwards compatibility, pass the token
266
+ # from the webapp settings.
267
+ token = self .settings .get ("token" , "<generated>" ),
268
+ # Prefix the cookie name with "model-" to avoid colliding with
269
+ # the cookie set by the classic server.
270
+ # NOTE: This creates two cookies to authenticate the user
271
+ # (1) the token cookie and (2) the user model cookie.
272
+ cookie_name = "model-" + self .settings .get ("cookie_name" , default_cookie_name ),
273
+ cookie_options = self .settings .get ("cookie_options" , {}),
274
+ secure_cookie = self .settings .get ("secure_cookie" , None ),
275
+ get_secure_cookie_kwargs = self .settings .get ("get_secure_cookie_kwargs" , {}),
257
276
)
258
277
return self .settings ["identity_provider" ]
259
278
0 commit comments