Okta认证Django [英] Okta Authentication Django

查看:694
本文介绍了Okta认证Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django应用程序,我正在尝试添加Okta身份验证。我目前已经创建了一个使用Okta API来验证用户的自定义后端:

 类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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆