Skip to main content

Django Integration with JustPass.me

Project description

Django Client for justpass.me

  1. Install the justpassme app

    • For django 2.2, use justpass-me-django<3.0.0
    • For django 3.1+, use justpass-me-django>3.0.0
    pip install justpass-me-django
    
  2. Add the following to your INSTALLED_APPS

    INSTALLED_APPS = [ 
    '....'
    'mozilla_django_oidc',
    'justpassme',
    '....'
    ]
    
  3. Add the following to settings.py

    AUTHENTICATION_BACKENDS = (
     'justpassme.OIDC_CLIENT.OIDCUserFinder',
     'django.contrib.auth.backends.ModelBackend',
     )
    
    
    SITE_URL = YOUR_SITE_URL   #Your full site url
    OIDC_USERNAME_FIELD = "username"   # The field to use to create users on justpass.me
    LOGIN_URL = "/accounts/login/"     # Your login view as usual
    
    OIDC_RP_CLIENT_ID = "app.client_id"      # client_id from justpass.me
    OIDC_RP_CLIENT_SECRET="app.client_secret" # client_secret from justpass.me
    OIDC_OP_URL= "https://organization_domain.accounts.justpass.me/openid/" #Put your organization domain on justpass.me
    
    OIDC_RP_SCOPES= "openid"
    OIDC_RP_SIGN_ALGO = 'HS256'
    OIDC_STORE_ID_TOKEN = True
    OIDC_OP_JWKS_ENDPOINT=OIDC_OP_URL  +"jwks"
    OIDC_OP_AUTHORIZATION_ENDPOINT=OIDC_OP_URL + "authorize/"
    OIDC_OP_TOKEN_ENDPOINT = OIDC_OP_URL +"token/"
    OIDC_OP_USER_ENDPOINT = OIDC_OP_URL + "userinfo/"
    OIDC_CALLBACK_CLASS= "justpass.OIDC_CLIENT.OIDCAuthn"
    OIDC_AUTHENTICATE_CLASS = "justpass.OIDC_CLIENT.OIDC_AUTHENTICATE"
    LOGIN_REDIRECT_URL_FAILURE="/justpass/failure/"
    LOGIN_REDIRECT_URL = "/justpass/success/"
    
    # If your application uses SSL.
    USE_X_FORWARDED_HOST = True
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
    
    
    # Provide the following functions that will be called when event is triggered, check example functions below
    REGISTRATION_SUCCESS = "Shop.justpass.reg_success"
    REGISTRATION_FAILURE = "Shop.justpass.reg_failure"
    AUTHENTICATION_SUCCESS = "Shop.justpass.auth_success"
    AUTHENTICATION_FAILURE = "Shop.justpass.auth_failure"
    
  4. Add justpass to your urls

    urls_patterns= [
    '...',
    path(r'justpass/', include('justpassme.urls')),
    path('oidc/',include('mozilla_django_oidc.urls')),
    '....',
     ]
    

Note: If you use justpass.me as 2nd factor

Break your login function, Usually your login function will check for username and password, log the user in if the username and password are correct and create the user session, to support justpass.me, this has to change

  • authenticate the user
  • if username and password are correct , check if the user has mfa or not
    • if user has mfa then redirect to justpass.me
    • if user doesn't have mfa then call your function to create the user session
  1. To start registration, go `justpass:reg``

    def start_reg(request):
        from justpassme.helpers import start_reg
        return start_reg(request)
    
  2. Write a function to start login and add it to your urls.py

    Note: The function expects the user username to be in request.session["base_username"]

    def start_login(request):
        from justpassme.helpers import start_oidc_sign
        return start_oidc_sign(request)
    
  3. Write 4 functions that handle the success and failure of registration and login. You can use the four functions below as a reference.

    def auth_success(request):
       return redirect('home')
          
    def auth_failure(request):
      return render(request, 'login.html', {"failed": True})
          
    def reg_success(request):
       request.user.mfa_enabled = True
       request.user.save()
       request.session["reg"] = True
       return redirect('home')
       
    def reg_failure(request):
       request.session["reg"] = False
       return redirect('home')
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

justpass-me-django-3.0.2.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file justpass-me-django-3.0.2.tar.gz.

File metadata

  • Download URL: justpass-me-django-3.0.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for justpass-me-django-3.0.2.tar.gz
Algorithm Hash digest
SHA256 feb3dadb57736bcb2b717784f2a9dc5ff49b1052ce5f79354489a831f19b224d
MD5 8faab1be45841cc3fb042975f964b17c
BLAKE2b-256 28a79acb518ccc7e2301d338ac309f0904f802fef533ea79eea1925a76568c67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page