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

Port OpenID Connect generics for DigiD/eHerkenning #69

Merged
merged 25 commits into from
Jun 11, 2024

Conversation

sergei-maertens
Copy link
Member

@sergei-maertens sergei-maertens commented May 24, 2024

This adds the optional dependency group oidc, which builds on top of mozilla-django-oidc-db.

The models and configuration are extracted from Open Forms, and the models have been renamed so that the meaning is better conveyed.

The test/CI setup is also updated, using the codecov flags feature to track the optional sub-package coverage "independently", but in a way that we verify the project still works without enabling the OIDC feature.

The next PR will change the model definitions to be able to configure more aspects.

@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from 26e7891 to 0bedd5c Compare May 28, 2024 10:03
This will allow us to make different test envs/builds to check the
correct functioning of the library with and without OIDC.
@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch 4 times, most recently from 6ba759d to e6a0213 Compare May 28, 2024 10:51
@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from e6a0213 to 7f257ad Compare May 28, 2024 10:55
@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from a4d2d7c to 4ddc79a Compare May 28, 2024 12:00
The OIDC subpackage is an optional feature that is tested separately
in CI.
@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from 4ddc79a to fa355ac Compare May 28, 2024 12:01
Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 97.36842% with 4 lines in your changes missing coverage. Please review.

Project coverage is 90.12%. Comparing base (acba57e) to head (c254231).
Report is 7 commits behind head on master.

Files Patch % Lines
digid_eherkenning/oidc/models/digid.py 92.30% 2 Missing ⚠️
digid_eherkenning/oidc/models/eherkenning.py 92.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #69      +/-   ##
==========================================
- Coverage   96.19%   90.12%   -6.08%     
==========================================
  Files          75       50      -25     
  Lines        3337     1569    -1768     
  Branches        0      142     +142     
==========================================
- Hits         3210     1414    -1796     
+ Misses        127      114      -13     
- Partials        0       41      +41     
Flag Coverage Δ
base 89.35% <100.00%> (?)
oidc 97.35% <97.35%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* Enable branch coverage measuring
* Hide 100% covered files in report
* Skip migrations from coverage reports
... and immediately some bugs were found and fixed.
I don't see a good way to ensure 100% test coverage, especially with
classes/models that are essentially intended to be subclassed further.
Subclassing models with proxies only to change a setting implemented
on the base class is quite excessive, especially because it makes
you override the admin registration. For callback view modifications,
we can optionally provide a django setting.
@sergei-maertens sergei-maertens requested a review from stevenbal May 28, 2024 13:38
@sergei-maertens sergei-maertens marked this pull request as ready for review May 28, 2024 13:38
@sergei-maertens
Copy link
Member Author

@stevenbal there will be more changes to the model fields/configuration aspects, so I'm skipping on those tests for now. I'm also not sure that 100% test coverage is possible since some sanity checks/building blocks are provided here that are intended to be consumed by backends/views defined in downstream projects 🤔

@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from 39ff789 to 98a1f02 Compare May 28, 2024 13:44
@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from 98a1f02 to 662de12 Compare May 28, 2024 13:46
@sergei-maertens sergei-maertens requested a review from vaszig May 31, 2024 08:11
So that downstream projects can import this too for type checks
and issubclass checks.
@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from 455c352 to 9012e74 Compare June 3, 2024 13:02
Ensure that our sanity check in the base class works
as expected for downstream projects wishing to
override the callback behaviour on a per-config
basis.
We don't support Django < 4.2 anymore.
@sergei-maertens sergei-maertens force-pushed the feature/oidc-generics branch from 3a62c3e to 200d987 Compare June 10, 2024 16:41
Copy link
Contributor

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some minor comments



class DigiDMachtigenConfig(OpenIDConnectBaseConfig):
# TODO: support periods in claim keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the ..._claim_name fields will probably be migrated to use ClaimField in a next PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly :-) and then I will add additional fields for the extra claims that need to be extracted, so I will make sure that's a single migration

The op_logout endpoint was provided in upstream, so the mapping in
the modelform factory no longer requires patching. Additionally,
the field is not necessarily required, so this requirement is
dropped too.
@stevenbal stevenbal self-requested a review June 11, 2024 11:35
@sergei-maertens sergei-maertens merged commit 0f75dbd into master Jun 11, 2024
14 of 16 checks passed
@sergei-maertens sergei-maertens deleted the feature/oidc-generics branch June 11, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants