Skip to content

Added a local identity provider. #1333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

3coins
Copy link
Collaborator

@3coins 3coins commented Apr 28, 2025

Partially fixes #1181, long term we might want to make an update to jupyter-server for local installations.

This PR adds a local identity provider to switch user identity to local host credentials. The identity provider is only appropriate for local installations of Jupyter.

jupyter lab --ServerApp.identity_provider_class=jupyter_ai.auth.identity.LocalIdentityProvider
Before After
Screenshot 2025-04-28 at 8 03 27 AM Screenshot 2025-04-28 at 8 05 16 AM

Note: Excluding the change to jupyter_ai.json, as I wasn't able to get this working, even though it is being copied to a directory in jupyter --paths.

(jupyter-ai) pijain@bcd07462b5c2 jupyter-ai % jupyter --paths
config:
    /Users/pijain/.jupyter
    /Users/pijain/.local/etc/jupyter
    /Users/pijain/miniforge3/envs/jupyter-ai/etc/jupyter
    /usr/local/etc/jupyter
    /etc/jupyter
data:
    /Users/pijain/Library/Jupyter
    /Users/pijain/.local/share/jupyter
    /Users/pijain/miniforge3/envs/jupyter-ai/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter
runtime:
    /Users/pijain/Library/Jupyter/runtime

(jupyter-ai) pijain@bcd07462b5c2 jupyter-ai % cat /Users/pijain/miniforge3/envs/jupyter-ai/etc/jupyter/jupyter_server_config.d/jupyter_ai.json
{
  "ServerApp": {
    "jpserver_extensions": {
      "jupyter_ai": true
    },
    "identity_provider_class": "jupyter_ai.auth.identity.LocalIdentityProvider"
  }
}%  

@srdas srdas added bug:confirmed Bugs that have been confirmed by maintainers bug Bugs reported by users and removed bug:confirmed Bugs that have been confirmed by maintainers labels Apr 28, 2025
@krassowski

This comment was marked as spam.

@3coins 3coins force-pushed the local-identity-provider branch from 308f800 to affd3f2 Compare April 28, 2025 15:38
@3coins 3coins marked this pull request as ready for review April 28, 2025 15:55
Copy link
Collaborator

@srdas srdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I tested it and it works, even without the --no-browser option.

Happy to approve once you are done with changes.

Copy link
Collaborator

@srdas srdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for closing this out!

from jupyter_server.auth.identity import IdentityProvider, User


def create_initials(username):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how long can username be?

if it's bounded it's fine, but line 13 is a loop within a loop so if username is large it could be expensive.
The variable name suggests it should be a small string in which case it's not really an issue.

Otherwise, one simple way to do it is to interrupt the loop on line 13 as soon as two consonants were found.



def create_initials(username):
"""Creates initials combining first 2 consonants"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not sure we care, but generally python docstring end w/ a period .

color=None,
)
return user
except OSError as e:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not using variable e, interesting that the linter isn't picking this up...

provider = LocalIdentityProvider(log=log)

user = provider.get_user(handler)
user = await user

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: variable redefinition, perhaps it's okay but just flagging it.

Also, why are we awaiting here? get_user is not async as far as I can tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs reported by users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v3.0.0ax] Always assigned an Anonymous username
5 participants