Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare release 0.0.14 #15

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
83e3f7f
config rework wik
regilero Jun 13, 2024
8b575dc
Settings rework: stable status.
regilero Jan 9, 2025
94285e5
Unit tests for settings.
regilero Jan 13, 2025
4bb0530
hook_validate_access_token and use_introspection_on_access_tokens.
regilero Jan 13, 2025
6a465f4
User hook function now have an OIDClient arg, use it to retrieve sett…
regilero Jan 13, 2025
8c77aef
Fix tests and bugs after last two commits.
regilero Jan 14, 2025
3a85cb8
Doc and minor fixs and renaming.
regilero Jan 14, 2025
de32195
Robustify code
gbip Jan 14, 2025
99ea5c7
Merge branch 'pfl-patches' into 'settings-rework'
regilero Jan 14, 2025
03ec990
New setting oidc_cache_provider_metadata_ttl, default 2 minutes (but …
regilero Jan 14, 2025
13ca6be
Fix the fix: use_introspection_on_access_tokens is a bool setting, an…
regilero Jan 14, 2025
c5ddfe6
small tweaks.
regilero Jan 14, 2025
c5cc4e5
review: remove OP_SETTINGS class var definition.
regilero Jan 14, 2025
fe0ddf3
Version bump 0.0.14
regilero Jan 14, 2025
bef249b
dev ux: allow provider_discovery_uri config for keycloakProvider inst…
regilero Jan 14, 2025
9bb29f0
Rework dependencies management
gbip Jan 15, 2025
d490df3
Merge branch 'mypy' into 'settings-rework'
gbip Jan 15, 2025
a4f2d8f
Fix dependencies
gbip Jan 15, 2025
e672f64
Fix type annotations
gbip Jan 15, 2025
bf2c158
Make implementation more robust by following type hints
gbip Jan 15, 2025
382a2b2
Add mypy configuration
gbip Jan 15, 2025
bbd0cb2
Add pre-commit hook for mypy
gbip Jan 15, 2025
1fd73c3
Switch build backend to hatch
gbip Jan 15, 2025
782bc65
Make the whole project python 3.8-compatible
gbip Jan 16, 2025
bd625e1
Merge branch 'mypy' into packaging
gbip Jan 16, 2025
a45d387
Fix Makefile
gbip Jan 16, 2025
d50021a
Freeze depencies for python 3.10
gbip Jan 16, 2025
4b71768
Stricter mypy configuration
gbip Jan 16, 2025
27c1c62
Enable mypy check 'disallow_incomplete_defs'
gbip Jan 16, 2025
9d6b973
Enable mypy check 'disallow_untyped_defs'
gbip Jan 16, 2025
a82b0d3
Enable mypy check 'no_implicit_reexport'
gbip Jan 16, 2025
1dbfa86
Enable more mypy checks
gbip Jan 16, 2025
2a2b0e1
Remove runtime type checks for configuration settings
gbip Jan 16, 2025
bda1b4c
Make type annotations python 3.8 compliant
gbip Jan 16, 2025
4d84b86
Merge branch 'mypy' into packaging
gbip Jan 16, 2025
eedc419
Fix OIDCView crashing
gbip Jan 16, 2025
f8bdff1
Fix typo
gbip Jan 16, 2025
625e9d0
Fix e2e tests
gbip Jan 16, 2025
ef04c5c
Remove unneeded cast
gbip Jan 16, 2025
ba814fa
Merge branch 'more_mypy' into 'mypy'
gbip Jan 16, 2025
b014c7d
Merge branch 'mypy' into 'settings-rework'
gbip Jan 16, 2025
f646553
Merge branch 'settings-rework' into packaging
gbip Jan 16, 2025
76863f8
Add hatch to test dependencies
gbip Jan 20, 2025
6334ec8
Fix django admin typing
gbip Jan 20, 2025
d11307f
Setup proper version detection
gbip Jan 20, 2025
4446d3f
Add publication instruction
gbip Jan 20, 2025
4106961
Merge branch 'packaging' into 'settings-rework'
gbip Jan 20, 2025
1e3e942
Setup linting with github ci
gbip Jan 20, 2025
f5dbeba
Pin black version and bump it
gbip Jan 20, 2025
3a73b17
Split build job
gbip Jan 20, 2025
c67d4ea
Fix
gbip Jan 20, 2025
0722611
Add mypy job
gbip Jan 20, 2025
87c1255
Restore mypy job
gbip Jan 20, 2025
91d309a
Fix dependencies installation
gbip Jan 23, 2025
a5ca475
Pin mypy version
gbip Jan 23, 2025
530d318
Add typing marker
gbip Jan 28, 2025
888ff9d
Merge pull request #16 from makinacorpus/setup_ci
gbip Feb 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyproject.toml export-subst
85 changes: 85 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Lint source code

on:
push:
branches: [ $default-branch ]
pull_request:

jobs:

black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: psf/black@stable
with:
version: "~= 24.0"

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for versioningit to find the repo version
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install --upgrade pip build
- name: Build python package
run: python -m build

mypy:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for versioningit to find the repo version
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: python -m pip install .[drf]

- name: Install dependencies
run: python -m pip install --upgrade pip
-r requirements/requirements-dev.in
-r requirements/requirements-test.in

- name: Run mypy
run: mypy --version && ./run_mypy.sh


linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for versioningit to find the repo version
- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: python -m pip download .[drf]

- name: Install dependencies
run: python -m pip install --upgrade pip
-r requirements/requirements-dev.in
-r requirements/requirements-test.in

- name: Run flake8
run : flake8 --version && flake8 --extend-ignore=E501,E503,E203 --max-line-len=88 .

- name: Run isort
run : isort --profile black .
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -15,4 +15,10 @@ repos:
- id: isort
args: ["--profile", "black"]
name: isort (python)

- repo: local
hooks:
- id: mypy
name: Mypy
entry: ./run_mypy.sh
language: script
pass_filenames: false
77 changes: 69 additions & 8 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
# Dev setup

## Publishing (test pypy)

First create an account on [test pypi]() and generate a token.

Clean your worktree and tag your release to generate a valid version number (otherwise pypi will reject your release) :

```
git stash # clean your worktree
git tag 0.0.18rc1
git stash pop # restore your worktree
```

Then, publish using the Makefile to build and push the library :

```
make clean && make build && make publish-test
```

## Publishing (production)

Make sure that you are on the maintainer list of the [pypi project](https://pypi.org/project/django-pyoidc/) and generate an API token for this project.

Clean your worktree and tag your release :

```
git stash # clean your worktree
git tag 0.0.1 # tag the release
git stash pop # tag your release
```

Build the python package :

```
make clean && make build
```

Publish it :

```
make publish
```


## Installation

```bash
pip install -r requirements.txt -r requirements-test.txt
pip install -r requirements/requirements.txt -r requirements/requirements-test.txt
```

## Enable pre-commit
Expand All @@ -20,27 +63,45 @@ Run a live documentation server :
sphinx-autobuild docs docs/_build/html
```

## Running static type checking (mypy)

First install the dev dependencies :

```
pip install -r requirements/requirements.txt -r requirements/requirements-dev.txt
```

Then run mypy :

```
mypy django_pyoidc
```

## Running Tests

Check database settings in tests/test_settings.py, target a real PostgreSQL Host (You need a PostgreSQL version 12 or greater).
Check database settings in `tests/test_settings.py`, target a real PostgreSQL Host (You need a PostgreSQL version 12 or greater), for e2e tests check the `tests/e2e/settings.py` file.

```
python3 runtests.py
python3 run_tests.py # for unit tests
python3 run_e2e_tests.py # for end to end tests
```

## Adding a dependency

Add the dependency to either `requirements.in` or `requirements-test.in`.
Add the dependency to either `requirements/requirements.in`, `requirements/requirements-test.in` or `requirements/requirements-dev.in`
depending on the usage of the dependency.

Then run :

```
pip install pip-tools
pip-compile --output-file=requirements.txt pyproject.toml # freeze package versions
pip-compile --output-file=requirements-test.txt requirements-test.in
make update_all_deps
```

FIXME: possible alternative for tests requirements would be:
## Building local packages

You can build the package locally by running :

```
python -m piptools compile --extra test -o requirements-test.txt pyproject.toml
python -m build
```
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.PHONY: update_all_deps build clean publish-test

update_all_deps : requirements/requirements.txt requirements/requirements-dev.txt requirements/requirements-test.txt


requirements/requirements.txt : pyproject.toml
pip-compile -o $@ $< --extra drf

requirements/requirements-dev.txt : requirements/requirements-dev.in requirements/requirements/requirements.txt
pip-compile -o $@ $<

requirements/requirements-test.txt : requirements/requirements-test.in requirements/requirements-dev.in requirements/requirements.txt
pip-compile $<

publish-test:
hatch publish -r test -u __token__

publish:
hatch publish -r main -u __token__

build:
hatch build

clean:
@rm -rf dist/
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Makina Django OIDC
# django-pyoidc


<p align="center">
Expand Down Expand Up @@ -90,19 +90,22 @@ Now you can pick an identity provider from the [available providers](https://dja

Create a file named `oidc.py` next to your settings file and initialize your provider there :

FIXME: Here config as settings only OR using custom provider

```python
from django_pyoidc.providers.keycloak import KeycloakProvider

my_oidc_provider = KeycloakProvider(
op_name="keycloak",
client_secret="s3cret",
client_id="my_client_id",
keycloak_base_uri="http://keycloak.local:8080/auth/", # we use the auth/ path prefix option on Keycloak
keycloak_realm="Demo",
client_secret="s3cret",
client_id="my_client_id",
logout_redirect="http://app.local:8082/",
failure_redirect="http://app.local:8082/",
success_redirect="http://app.local:8082/",
redirect_requires_https=False,
login_uris_redirect_allowed_hosts=["app.local:8082"],
)
```

Expand All @@ -112,7 +115,7 @@ You can then add to your django configuration the following line :
from .oidc_providers import my_oidc_provider

DJANGO_PYOIDC = {
**my_oidc_provider.get_config(allowed_hosts=["app.local:8082"]),
**my_oidc_provider.get_config(),
}
```

Expand Down Expand Up @@ -153,4 +156,3 @@ This project is sponsored by Makina Corpus. If you require assistance on your pr

- [@gbip](https://www.github.com/gbip)
- [@regilero](https://github.com/regilero)

2 changes: 1 addition & 1 deletion django_pyoidc/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.13
0.0.14
7 changes: 4 additions & 3 deletions django_pyoidc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Any, Dict

from django.contrib.auth import get_user_model
from django.core.exceptions import SuspiciousOperation
Expand All @@ -7,7 +7,7 @@
from django_pyoidc.utils import extract_claim_from_tokens


def get_user_by_email(tokens: Dict):
def get_user_by_email(tokens: Dict[str, Any]) -> Any:
User = get_user_model()

username = None
Expand Down Expand Up @@ -71,5 +71,6 @@ def get_user_by_email(tokens: Dict):
email=email,
username=django_username,
)
user.backend = "django.contrib.auth.backends.ModelBackend"
if hasattr(user, "backend"):
user.backend = "django.contrib.auth.backends.ModelBackend"
return user
13 changes: 7 additions & 6 deletions django_pyoidc/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from django.conf import settings
from django.contrib import admin

from django_pyoidc.models import OIDCSession

SessionStore = import_module(settings.SESSION_ENGINE).SessionStore


class OIDCSessionAdmin(admin.ModelAdmin):
class OIDCSessionAdmin(admin.ModelAdmin): # type: ignore[type-arg] # https://github.com/typeddjango/django-stubs/issues/507
readonly_fields = (
"state",
"session_state",
Expand All @@ -24,12 +26,11 @@ class OIDCSessionAdmin(admin.ModelAdmin):
"created_at",
]

def has_session_management(self, obj) -> bool:
@admin.display(boolean=True)
def has_session_management(self, obj: OIDCSession) -> bool:
return obj.session_state is not None

def session_is_active(self, obj) -> bool:
@admin.display(boolean=True)
def session_is_active(self, obj: OIDCSession) -> bool:
s = SessionStore()
return obj.cache_session_key is not None and s.exists(obj.cache_session_key)

has_session_management.boolean = True
session_is_active.boolean = True
Loading