Git Product home page Git Product logo

okta-django-samples's Introduction

Okta OpenID Connect/OAuth2 Sample in Django

This sample provides an example of using Okta to login to a Django application. We use the Okta Sign-In Widget to quickly add an Okta login interface to the Django app.

Architecturally, Okta acts as an Identity Provider external to Django and integrates using OpenID Connect: The user is authenticated by Okta, which sends OpenID Connect id_token (and optionally access_token) to a callback controller that will validate the token(s). Upon successful validation, login the user (if existing) else Just-in-time "JIT" provision the Django user. This end-to-end process is akin to Okta doing a Single-Sign-On into Django.

For completeness, we stack the @login_required decorator with a custom @okta_login_required decorator, which checks if JWT token(s) were successfully retrieved from Okta. Additional custom validations (e.g. checking for certain claims - such as role information - in the token(s)) would/cloud be placed in the custom decorator as well.

This project is written in Python 3.6 and Django 2

Running the Sample

Pre-requisites

If you do not have an Okta account, please sign up here.

Basic setup:

You may tweak settings later as you gain more familiarity with the Okta platform. For starting out however, simply follow these instructions closely

  1. Under the Applications menu, click Add Application and select Web
  2. Click Next, then enter an Application Name. Then:
    • Set Base URIs to http://localhost:8000/
    • Add http://localhost:8000/oauth2/callback/ the list of Redirect URIs
    • Leave the default setting, Group assignments = Everyone
  3. Click Done to redirect back to the General tab of your application.
  4. Make note of the Client ID and Client Secret, as it will be needed environment configuration
  5. Navigate to the Dashboard menu of your Developer Console. Make note of the Org URL value found on the top right-hand corner of the screen
  6. Edit the .env file included in this sample:
    • Provide the value for ORG_URL from step 5 above
    • Provide the value for ISSUER, by concatenating "/oauth2/default" to the ORG_URL value
    • Provide values for CLIENT_ID and CLIENT_SECRET, both obtained in step 4 above
    • Leave the values for SCOPES and REDIRECT_URI as-is
  7. Enable CORS access to your Okta org
    • In the navigation menu, select API then Trusted Origins
    • Click Add Origin
    • Set Origin URL = http://localhost:8000 and check the box CORS
    • Save

Build Instructions

Use the following commands on Mac OS X or Linux:

    $ python3 -m venv venv
    $ source venv/bin/activate
    $ pip install -r requirements.txt

Run migrations (In this sample we're simply using sqlite); Tables are needed for session management.

    $ python manage.py migrate

Run the Sample

Source the environment variables (.env file)

    $ source .env

Start the web server with python manage.py runserver

    $ python manage.py runserver

Navigate to http://localhost:8000 to login using the Okta Sign-In Widget

okta-django-samples's People

Contributors

deadbeef404 avatar dependabot[bot] avatar westsaharut avatar zeekhoo avatar zeekhoo-okta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.