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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With