Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from jupyterhub.auth import LocalAuthenticator
from .oauth2 import OAuthLoginHandler, OAuthenticator
OKPY_USER_URL = "https://okpy.org/api/v3/user"
OKPY_ACCESS_TOKEN_URL = "https://okpy.org/oauth/token"
OKPY_AUTHORIZE_URL = "https://okpy.org/oauth/authorize"
class OkpyMixin(OAuth2Mixin):
_OAUTH_ACCESS_TOKEN_URL = OKPY_ACCESS_TOKEN_URL
_OAUTH_AUTHORIZE_URL = OKPY_AUTHORIZE_URL
class OkpyLoginHandler(OAuthLoginHandler, OkpyMixin):
pass
class OkpyOAuthenticator(OAuthenticator, OAuth2Mixin):
login_service = "Okpy"
login_handler = OkpyLoginHandler
@default('scope')
def _default_scope(self):
return ['email']
def get_auth_request(self, code):
params = dict(
redirect_uri = self.oauth_callback_url,
code = code,
grant_type = 'authorization_code'
from .oauth2 import OAuthLoginHandler, OAuthenticator
def _api_headers(access_token):
return {"Accept": "application/json",
"User-Agent": "JupyterHub",
"Authorization": "Bearer {}".format(access_token)
}
class BitbucketMixin(OAuth2Mixin):
_OAUTH_AUTHORIZE_URL = "https://bitbucket.org/site/oauth2/authorize"
_OAUTH_ACCESS_TOKEN_URL = "https://bitbucket.org/site/oauth2/access_token"
class BitbucketLoginHandler(OAuthLoginHandler, BitbucketMixin):
pass
class BitbucketOAuthenticator(OAuthenticator):
login_service = "Bitbucket"
client_id_env = 'BITBUCKET_CLIENT_ID'
client_secret_env = 'BITBUCKET_CLIENT_SECRET'
login_handler = BitbucketLoginHandler
team_whitelist = Set(
config=True,
help="Automatically whitelist members of selected teams",
)
bitbucket_team_whitelist = team_whitelist
from jupyterhub.auth import LocalAuthenticator
from oauthenticator.oauth2 import OAuthLoginHandler, OAuthenticator
from tornado.auth import OAuth2Mixin
from tornado.httputil import url_concat
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError
class MyServiceMixin(OAuth2Mixin):
# authorize is the URL users are redirected to to authorize your service
_OAUTH_AUTHORIZE_URL = "https://myservice.biz/login/oauth/authorize"
# token is the URL JupyterHub accesses to finish the OAuth process
_OAUTH_ACCESS_TOKEN_URL = "https://myservice.biz/login/oauth/access_token"
class MyServiceLoginHandler(OAuthLoginHandler, MyServiceMixin):
pass
class GitHubOAuthenticator(OAuthenticator):
# login_service is the text displayed on the "Login with..." button
login_service = "My Service"
login_handler = MyServiceLoginHandler
async def authenticate(self, handler, data=None):
"""We set up auth_state based on additional GitHub info if we
receive it.
"""
code = handler.get_argument("code")
# TODO: Configure the curl_httpclient for tornado
from traitlets import Unicode, List, Bool, validate
from jupyterhub.auth import LocalAuthenticator
from .oauth2 import OAuthLoginHandler, OAuthenticator
CILOGON_HOST = os.environ.get('CILOGON_HOST') or 'cilogon.org'
class CILogonMixin(OAuth2Mixin):
_OAUTH_AUTHORIZE_URL = "https://%s/authorize" % CILOGON_HOST
_OAUTH_TOKEN_URL = "https://%s/oauth2/token" % CILOGON_HOST
class CILogonLoginHandler(OAuthLoginHandler, CILogonMixin):
"""See http://www.cilogon.org/oidc for general information."""
def authorize_redirect(self, *args, **kwargs):
"""Add idp, skin to redirect params"""
extra_params = kwargs.setdefault('extra_params', {})
if self.authenticator.idp:
extra_params["selected_idp"] = self.authenticator.idp
if self.authenticator.skin:
extra_params["skin"] = self.authenticator.skin
return super().authorize_redirect(*args, **kwargs)
class CILogonOAuthenticator(OAuthenticator):
login_service = "CILogon"
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from jupyterhub.auth import LocalAuthenticator
from .oauth2 import OAuthLoginHandler, OAuthenticator
OPENSHIFT_URL = os.environ.get('OPENSHIFT_URL') or 'https://localhost:8443'
OPENSHIFT_AUTH_API_URL = os.environ.get('OPENSHIFT_AUTH_API_URL') or OPENSHIFT_URL
OPENSHIFT_REST_API_URL = os.environ.get('OPENSHIFT_REST_API_URL') or OPENSHIFT_URL
class OpenShiftMixin(OAuth2Mixin):
_OAUTH_AUTHORIZE_URL = "%s/oauth/authorize" % OPENSHIFT_AUTH_API_URL
_OAUTH_ACCESS_TOKEN_URL = "%s/oauth/token" % OPENSHIFT_AUTH_API_URL
class OpenShiftLoginHandler(OAuthLoginHandler, OpenShiftMixin):
# This allows `Service Accounts as OAuth Clients` scenario
# https://docs.openshift.org/latest/architecture/additional_concepts/authentication.html#service-accounts-as-oauth-clients
@property
def scope(self):
return self.authenticator.scope
class OpenShiftOAuthenticator(OAuthenticator):
login_service = "OpenShift"
login_handler = OpenShiftLoginHandler
scope = ['user:info']
users_rest_api_path = '/apis/user.openshift.io/v1/users/~'
GITLAB_API = '%s/api/v%s' % (GITLAB_URL, GITLAB_API_VERSION)
def _api_headers(access_token):
return {"Accept": "application/json",
"User-Agent": "JupyterHub",
"Authorization": "Bearer {}".format(access_token)
}
class GitLabMixin(OAuth2Mixin):
_OAUTH_AUTHORIZE_URL = "%s/oauth/authorize" % GITLAB_URL
_OAUTH_ACCESS_TOKEN_URL = "%s/oauth/access_token" % GITLAB_URL
class GitLabLoginHandler(OAuthLoginHandler, GitLabMixin):
pass
class GitLabOAuthenticator(OAuthenticator):
# see gitlab_scopes.md for details about scope config
# set scopes via config, e.g.
# c.GitLabOAuthenticator.scope = ['read_user']
login_service = "GitLab"
client_id_env = 'GITLAB_CLIENT_ID'
client_secret_env = 'GITLAB_CLIENT_SECRET'
login_handler = GitLabLoginHandler
gitlab_group_whitelist = Set(
config=True,