OAuthenticator:使用通用OAuth提供程序验证JupyterHub用户

oauthenticator的Python项目详细描述


OAuthenticator

oauth+jupyterhub authenticator=oauthenticator

OAuthenticator当前支持以下身份验证服务:

a通用实现,可以与 也提供任何提供商。

示例

有关使用OAuthenticator的Docker映像示例,请参见示例 目录。

另一个示例 正在使用github oauth在单独的docker中生成每个用户的服务器 容器。

安装

使用pip安装:

pip3 install oauthenticator

或者克隆repo并进行dev安装:

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .

一般设置

第一步是告诉jupyterhub使用您选择的oauthenticator。各 authenticator在oauthenticator的子模块中提供,并且每个 authenticator有一个带有local的变量(例如localgithuboauthenticator), 将OAuth用户名映射到本地系统用户名。

设置选定的OAuthenticator

在jupyterhub配置py中,添加:

fromoauthenticator.githubimportGitHubOAuthenticatorc.JupyterHub.authenticator_class=GitHubOAuthenticator

设置回调URL、客户端ID和客户端机密

所有OAuthenticator都需要设置回调URL、客户端ID和客户端 秘密。通常在注册oauth应用程序时会得到这些 与您的oauth提供者。特定于提供程序的详细信息在部分中提供 下面。在向您的提供商注册OAuth应用程序时,您将 可能需要指定回调URL。 回调url应该如下所示:

http[s]://[your-host]/hub/oauth_callback

其中[主机]是服务器将运行的位置。如 example.com:8000

当jupyterhub运行时,将从环境变量中检索这些值:

$OAUTH_CALLBACK_URL$OAUTH_CLIENT_ID$OAUTH_CLIENT_SECRET

您还可以在配置文件中设置这些值

c.MyOAuthenticator.oauth_callback_url='http[s]://[your-host]/hub/oauth_callback'c.MyOAuthenticator.client_id='your-client-id'c.MyOAuthenticator.client_secret='your-client-secret'

azure设置

先决条件
  • 要求:pyjwt>;=1.5.3
> pip3 install PyJWT
  • 请确保设置环境变量
> export AAD_TENANT_ID='{AAD-TENANT-ID}'
  • 示例代码在examples>;azuread>;sample_jupyter_config.py中提供
  • 只需将下面的代码添加到您的jupyterhub\u config.py文件中
  • 确保将'{}'中的值替换为应用程序、租户、域等的值
< Buff行情>

按照此链接创建aad应用程序< Buff行情>

客户端ID===azure应用程序ID-可在azure门户-->;ad-->;应用程序注册-->;应用程序中找到 < Buff行情>

租户id===azure目录id-可在azure门户-->;ad-->;属性中找到

jupyterhub配置py:

import os
from oauthenticator.azuread import AzureAdOAuthenticator
c.JupyterHub.authenticator_class = AzureAdOAuthenticator

c.Application.log_level = 'DEBUG'

c.AzureAdOAuthenticator.tenant_id = os.environ.get('AAD_TENANT_ID')

c.AzureAdOAuthenticator.oauth_callback_url = 'http://{your-domain}/hub/oauth_callback'
c.AzureAdOAuthenticator.client_id = '{AAD-APP-CLIENT-ID}'
c.AzureAdOAuthenticator.client_secret = '{AAD-APP-CLIENT-SECRET}'

通过运行:

αααα10 < Buff行情>

请参见run.sh以获取示例。

GitHub设置

首先,您需要创建一个github oauth 应用程序

然后,将以下内容添加到您的jupyterhub_config.py文件中:

pip3 install oauthenticator
1

您还可以使用localgithuboauthenticator将github帐户映射到本地用户。

通过设置环境变量,您可以使用自己的github企业实例。

如果您的github企业只支持http,则可以将环境变量设置为true或任何设置。

Github允许通过 将特定于github的作用域添加到请求的令牌。

Gitlab设置

首先,您需要创建一个gitlab oauth 应用程序

然后,将以下内容添加到您的jupyterhub_config.py文件中:

pip3 install oauthenticator
2

您还可以使用localgitlaboauthenticator将gitlab帐户映射到本地用户。

您可以通过设置gitlab_host环境来使用自己的gitlab ce/ee实例 旗.

谷歌设置

访问https://console.developers.google.com" rel="nofollow">https://console.developers.google.com设置OAuth客户端ID和机密。有关如何创建OAuth 2.0客户端凭据,请参见谷歌文档授权的javascript源代码应设置为集线器的公共地址,而授权的重定向uri应设置为相同,但后面紧跟/hub/oauth_回调

然后,将以下内容添加到您的jupyterhub_config.py文件中:

pip3 install oauthenticator
3

默认情况下,允许任何域登录,但您可以使用列表(推荐)限制授权域:

pip3 install oauthenticator
4

您可以自定义登录按钮文本(可选):

pip3 install oauthenticator
5

打开换档设置

如果您使用正确配置的oauth进行openshift部署(请参见 下面几节是快速参考),您应该设置客户机ID和 环境变量的secretoauth_client_idoauth_client_secretoauth_callback_url

在openshift 4.0之前,oauth提供者和rest api url端点可以 通过设置单个环境变量openshift_url来指定。从 openshift 4.0以后,这两个端点位于不同的主机上。你需要 将openshift-auth-api-url设置为oauth提供程序url,然后 openshift_rest_api_url到rest api url端点。

oauth_回调url应该匹配http[s]://[your app route]/hub/oauth_回调

全球OAuth(管理员)

作为集群管理员,您可以创建一个全局的oauth客户端 在openshift集群中,使用api创建新的oauthclient对象:

pip3 install oauthenticator
6

作为OAuth客户端的服务帐户

作为项目成员,您可以将服务帐户用作oauth客户机" rel="nofollow">服务帐户用作oauth客户机 脚本。这使您可以定义与 服务帐户。您只需要使用 正确的注释:

pip3 install oauthenticator
7

在这种情况下,您的oauth_client_id将是系统:ServiceAccount:<;ServiceAccount_namespace>;:<;ServiceAccount_name&< /代码> oauth_client_secret是服务帐户的api令牌(oc sa get token<;service account_name>;) 而oauth_callback_url是注释serviceaccounts.openshift.io/oauth redirecturi.1的值。 更多详细信息请参见上游文档。

okpyauthenticator

okpy是一个自动评分工具 广泛应用于加州大学伯克利分校的eecs和数据科学课程。这个验证者 通过使学生能够通过 首先保存相关的用户状态 到env(在开发安全状态保存机制之前,该功能将被编辑)。

配置

如果要使用okpyauthenticator对集线器进行身份验证,则需要指定 jupyterhub config.py文件中的authenticator类:

pip3 install oauthenticator
8

并设置环境变量。

globus设置

访问https://developers.globus.org/" rel="nofollow">https://developers.globus.org/设置应用程序。确保本机应用程序 取消选中并确保回调url如下所示:

pip3 install oauthenticator
9

设置授权和传输的作用域。默认值包括:

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
0

jupyterhub配置中设置上述设置

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
1

或者,您可以为以下对象设置env变量:oauth_callback_urloauth_client_id, 以及oauth_client_secret。需要设置jupyterhub_crypt_key,并且可以生成 使用openssl:openssl rand-hex 32

你们都被这一点给定了!一定要检查下面的调整设置 与用户身份、传输和附加安全性相关。

用户身份

默认情况下,所有用户都被限制在其globus idexample@globusid.org) 使用默认的jupyterhub配置:

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
2

如果要使用链接标识,例如malcolm@universityofindependence.edu, 转到您的应用程序开发人员页面并设置 您的应用程序所需的身份提供程序设置为<;your university>;,并设置 配置如下:

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
3

全球范围和转移

默认配置将使用令牌自动设置用户环境, 允许他们启动python笔记本并启动globus传输。如果你 要将数据传输到jupyterhub服务器,建议您安装 globus connect server并在下面添加globus戋u local戋端点uuid。如果你想要 要更改其他行为,可以修改以下默认设置:

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
4

如果您只想用globus id验证用户,但不想 允许他们进行传输,您可以删除urn:globus:auth:scope:transfer.api.globus.org:all。 相反,如果愿意,可以为另一个传输服务器添加一个附加作用域。

使用c.globusoauthenticator.exclude防止令牌传递到 用户环境。默认情况下,auth.globus.org被排除在外,但transfer.api.globus.org 是允许的。如果要禁用传输,请修改c.globusoauthenticator.scope 而不是c.globusoauthenticator.exclude来避免获取不必要的令牌。

moodle设置

首先为moodle安装oauth2服务器插件

为jupyterhub使用genericoauthenticator,方法是相应地编辑jupyterhub配置py

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
5

并将环境变量oauth2\u authorize\u url设置为:

http://your-moodle-domain.com/local/oauth/login.php?客户ID=moodle-client-id&response\u type=code

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java中的else if语句返回语法错误   http如何解析从表单到REST Java/Webservice的post请求   java如何在SpringBoot中为RestTemplate编写JUnit测试   java动态检查实例是否实现接口   java在Android中使用ArrayAdaptor时,数据不会显示   根据前序遍历返回二进制树的java方法   Arquillian测试类中的java注入始终为空   用户界面Java Swing自定义控件   java使用CompletableFutures递归地从同一函数的多个调用构建列表   在Java中将“.00”添加到整数BigDecimal   卡夫卡java未知\u主题\u或\u部分错误间歇性   java为什么我的getString()方法总是返回null?   java renameTo无法重命名文件   java为什么我可以强制转换对象?可以用其他对象来完成吗?   带有回写条件的java多根记录器   关于stackoverflow错误的java帮助?   java Websphere消息队列多线程   Java图形窗口/画布未垂直显示完整的六边形网格   java Sakai未在Tomcat服务器中启动