Skip to main content

OpenID Connect client that works with GOV.UK One Login

Project description

govuk-onelogin-django

OpenID Connect client that works with GOV.UK One Login.

Package provides the following endpoints:

  • one-login/login/ to login via GOV.UK One Login.
  • one-login/callback/ endpoint GOV.UK One Login will send logged-in users back to.
  • back-channel-logout/ endpoint GOV.UK One Login will send logout notifications to.

The example project also provides an example logout view that will log the user out of your service as well as GOV.UK One Login.

See class ExampleLogoutView for example that includes post_logout_redirect_uri

Documentation:

Quick start

Before starting, you should create an example app using the GOV.OK One Login admin tool.

  1. Add "govuk_onelogin_django" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...,
        "govuk_onelogin_django",
    ]
    
  2. Include the govuk_onelogin_django URLconf in your project urls.py like this:

    path("one-login/", include("govuk_onelogin_django.urls")),
    
  3. Include OneLoginBackend to your AUTHENTICATION_BACKENDS like this:

    AUTHENTICATION_BACKENDS.append("govuk_onelogin_django.backends.OneLoginBackend")
    
  4. Include the following settings in your settings.py file

    # Required start page that includes a link to log in to GOV.UK One Login
    LOGIN_URL = "your-login-start-page"
    # A view name that the logged-in user will be redirected to after logging in via GOV.UK One Login
    LOGIN_REDIRECT_URL = "view-to-send-logged-in-users-to"
    
    # All other GOV.UK One Login settings required to configure govuk-onelogin-django
    GOV_UK_ONE_LOGIN_CLIENT_ID = "Your client ID"
    GOV_UK_ONE_LOGIN_CLIENT_SECRET = "Your client secret"
    GOV_UK_ONE_LOGIN_OPENID_CONFIG_URL = "Either integration or production config url."
    GOV_UK_ONE_LOGIN_SCOPE = "Required scopes"
    GOV_UK_ONE_LOGIN_AUTHENTICATION_LEVEL = "Required authentication level"
    GOV_UK_ONE_LOGIN_CONFIDENCE_LEVEL = "Required confidence level"
    

    Note: GOV_UK_ONE_LOGIN_CLIENT_SECRET is a base64 encoded string of your private key. e.g. base64 -i private_key.pem

    See this document detailing how to generate your keys.

Configuration

See configuration document detailing how to override the following:

  • Service logout behaviour of back-channel-logout/ endpoint
  • Override how GOV.UK One Login config is fetched
  • how GOV_UK_ONE_LOGIN_CLIENT_ID is loaded
  • How GOV_UK_ONE_LOGIN_CLIENT_SECRET is loaded

Example project

See the example_project README.md for details on how to build and run the example project.

Commands to build and test govuk-onelogin-django

  • Install uv
  • Update the project's environment: uv sync
  • Run tests using local venv: uv run pytest
  • Running the tests against all supported python versions:
    • Install tox and tox-uv: uv tool install tox --with tox-uv
    • Check tox is installed: tox --version
    • run the tests: tox run
  • Install pre-commit hooks: uv run pre-commit install
  • Run pre-commit against all files: uv run pre-commit run --all-files

linting / formatting

  • Run the Ruff linter: uv run ruff check
  • Resolve fixable errors: uv run ruff check --fix
  • Run the Ruff formatter: uv run ruff format
  • mypy: uv run mypy --config-file=pyproject.toml

Publishing

  • View the current project version: uv version
  • Update the project version with dryrun: uv version --bump minor --dry-run
  • Update the project version: uv version --bump minor
  • Publish to PyPI: uv publish --token <token>

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

govuk_onelogin_django-0.4.15.tar.gz (80.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

govuk_onelogin_django-0.4.15-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file govuk_onelogin_django-0.4.15.tar.gz.

File metadata

  • Download URL: govuk_onelogin_django-0.4.15.tar.gz
  • Upload date:
  • Size: 80.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for govuk_onelogin_django-0.4.15.tar.gz
Algorithm Hash digest
SHA256 fba5ff7f16bcf636af0ff396cab07f76f14ed167fd3619f8d74c6bb2d44089dc
MD5 03db0427f156fbf7a2fb4c3d9191f0d8
BLAKE2b-256 fdb3f3aebb81c74e4926e7f33ff994a63dbb0ee843893fd80a93d02f9f1dd4c5

See more details on using hashes here.

File details

Details for the file govuk_onelogin_django-0.4.15-py3-none-any.whl.

File metadata

  • Download URL: govuk_onelogin_django-0.4.15-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for govuk_onelogin_django-0.4.15-py3-none-any.whl
Algorithm Hash digest
SHA256 c909944aaf6d48b0ed0a85c91c96ba24c771febbc63c0648e5d884f493b01e12
MD5 4b1beaa79ed9a7e273d498f3b757652b
BLAKE2b-256 f53f00f31ca29536fa9d404fa6306688a447067ba31e27c594e6418c75782840

See more details on using hashes here.

Supported by

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