Okta认证Django [英] Okta Authentication Django
问题描述
类OKTABackend(ModelBackend):
def __init __(self,* args,** kwargs):
super().__ init __(* args,** kwargs)
def authenticate(self,username =没有,密码=无):
标头= {
'授权':'SSWS {}'格式(<我的OKTA API令牌>),
'接受' json',
'Content-type':'application / json'
}
authentication_payload = {
'username':username,
'password':password
}
r = requests.post(
<我的OKTA应用程序地址>
headers = headers,
data = json.dumps(authentication_payload)
)
try:
r.raise_for_status()
#查找/创建和返回用户
的代码,除了
返回无
I拥有一个具有用户名和密码的表单的登录页面,并将该信息传递给该后端进行身份验证。所有这一切都在工作。但是当我去OKTA网站,点击我的应用程序,我想要它登录到应用程序。目前它只是重定向到我的登录页面。如何启用从OKTA网站登录到我的应用程序?
您现在不必自己实现。只需使用现成的解决方案:
https://github.com/fangli / django-saml2-auth
它可以顺利地使用okta。
PS我是这个插件的作者。
I have a Django app that I am trying to add Okta authentication. I currently have created a custom backend that utilizes the Okta API to authenticate a user:
class OKTABackend(ModelBackend):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def authenticate(self, username=None, password=None):
headers = {
'Authorization': 'SSWS {}'.format(<my OKTA API token>),
'Accept': 'application/json',
'Content-type': 'application/json'
}
authentication_payload = {
'username': username,
'password': password
}
r = requests.post(
<my OKTA app address>,
headers=headers,
data=json.dumps(authentication_payload)
)
try:
r.raise_for_status()
# code that finds/creates and returns user
except:
return None
I have a login page with a form that gets the username and password and passes the information to this backend for authentication. All of this is working. But when I go to the OKTA site, and click on my app, I want it to sign into the app. Currently it just redirects to my login page. How do I enable sign on from the OKTA site into my app?
You don't have to implement it yourself now. just use the out-of-box solution: https://github.com/fangli/django-saml2-auth
It works with okta smoothly.
P.S. I'm the author of this plugin.
这篇关于Okta认证Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!