Skip to content
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

[Globus] Support custom username handling #357

Merged

Conversation

NickolausDS
Copy link
Contributor

Move the code responsible for fetching the username to a separate get_username() method so it can be overridden.

An example is running a Globus Jupyterhub Server that can accept logins from one or more providers (Google, ORCID, Any university in CILogon, etc.), wants needs to ensure usernames are unique. That way, person@uchicago.edu and person@gmail.com are assigned different usernames. The jupyterhub config could look like this:

import base64

class OmniProviderOAuthenticator(LocalGlobusOAuthenticator):
    def get_username(self, user_info):
        username, domain = user_info.get('preferred_username').split('@', 1)
        # 'sub' is a uniquely generated uuid by Globus for each user identity
        enc_sub = base64.b32encode(bytes(user_info['sub'], 'utf-8')).decode('utf-8')
        return f'{username}-{enc_sub}'[:32]

c.JupyterHub.authenticator_class = OmniProviderOAuthenticator

This is similar to the GenericOAuthenticator username picker, except the key in Globus will never change, so a callable is always preferred.

Move the code responsible for fetching the username to a separate
get_username() method so it can be overridden. This allows for
resolving conflicts when using multiple providers.
Copy link
Member

@GeorgianaElena GeorgianaElena left a comment

Choose a reason for hiding this comment

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

Thanks @NickolausDS 🎉

@GeorgianaElena GeorgianaElena merged commit cb6e579 into jupyterhub:master Jun 18, 2020
@NickolausDS
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants