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

Merged
merged 6 commits into from
May 6, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/jupyter-ai/jupyter_ai/auth/identity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import getpass

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"""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 .


username = username.lower()

# Default: return first two unique consonants
consonants = [c for c in username if c in "bcdfghjklmnpqrstvwxyz"]
if len(consonants) >= 2:
return (consonants[0] + consonants[1]).upper()

# Fallback: first two characters
return username[:2].upper()


class LocalIdentityProvider(IdentityProvider):

def get_user(self, handler):
username = getpass.getuser()
user = User(
username=username,
name=username,
initials=create_initials(username),
color=None,
)
return user
Loading