Django应用程序,用于使用IIT Bombay gymkhana SSO进行LDAP身份验证。
iitb-oauth的Python项目详细描述
Django Oauth2客户端使用IIT Bombay gymkhana SSO进行身份验证
使用IIT Bombay gymkhana SSO进行LDAP身份验证的小软件包。在
动机
SSO可能是一个棘手的事情设置和错误可能是耗时的调试。随着人们从PHP转移到Django和node,这个模块可以用来快速定义自定义回调,将从IIT Bombay gymkhana SSO获得的用户详细信息映射到Django用户模型。一旦用户通过身份验证,您就可以快速、轻松地以编程方式创建用户。在
在应用程序中设置
要使用此Django应用程序,必须执行以下步骤:
INSTALLED_APPS=[# ...'iitb_oauth'# ...]^{pr2}$
步骤2:将oauth URL添加到根网站:
urlpatterns=[# ...url(r'',include('iitb_oauth.urls')),# ...]
步骤3:为应用程序添加登录URL和相应的OAUTH配置设置。
还要添加FALLBACK_URL
作为OAuth身份验证失败时的备用。示例:
AUTH_PROFILE_MODULE=""# In case User has a user profile, specify the class hereLOGIN_URL="/login/"FALLBACK_URL="/"# In case user is not logged in or doesn't have enough permissions to view the contentCLIENT_ID='my-id'CLIENT_SECRET='<secret>'SCOPE='ldap'# ldap is necessary for login, pass only necessary scopes. seperate with spaces# Eg: SCOPE = 'profile ldap program'FIELDS='username'# username is mandatory field. seperate with commas# Eg: FIELDS = 'username,first_name,last_name,email,roll_number'REDIRECT_URI='<app_redirect_url>'# should end with /oauth/complete (the view is provided by this app)LOGIN_COMPLETE_REDIRECT='/some/url/in/your/app'LOGOUT_REDIRECT='/'# redirect to this URL after logout.MAPPINGS={# fields in User model: "LDAP attributes"# email mapped with username@iitb.ac.in if email is not in scope."first_name":"first_name","last_name":"last_name"}# In case a custom User model is defined, map fields in User model: "LDAP attributes"PROFILE_MAPPING={# Maps fields in user profile with response recieved from sso server.# AUTH_PROFILE_MODULE needs to be specified for this to work."roll_number":"roll_number"}
使用
一旦您尝试访问某个顶端有@login_required
装饰符的端点,您将被重定向到您定义的登录URI。用户使用IITB gymkhana SSO和您提供的任何其他后端进行身份验证。认证成功后,调用LOGIN_COMPLETE_REDIRECT
中指定的url,并使用回调将用户塑造成您提供的表单。如果由于任何原因身份验证失败或者用户没有权限,他将被重定向到FALLBACK_URL
中指定的URI。在
许可证
麻省理工学院
- 项目
标签: