Skip to content

feat: add pkce-openid-backend - #255

Merged
johanseto merged 6 commits into
v6.1.0-nelpfrom
jlc/add-pkce-openid-backend
Nov 21, 2023
Merged

feat: add pkce-openid-backend#255
johanseto merged 6 commits into
v6.1.0-nelpfrom
jlc/add-pkce-openid-backend

Conversation

@johanseto

Copy link
Copy Markdown
Contributor

Description

This adds a generic backend based on ConfigurableOpenIdConnectAuth but
with PKCE.
This backend is inspired by the social-core way to implement PKCE.
There is a current PR in work, but for the moment, that class is not merged and accessible.
So after that is finished this has its code for code_challenge and code_challenge_methodimplementation.
PR: python-social-auth/social-core#856

Testing instructions

Please provide detailed step-by-step instructions for testing this change.

Additional information

Jira story
https://edunext.atlassian.net/browse/FUTUREX-606

Checklist for Merge

  • Tested in a remote environment
  • Updated documentation
  • Rebased master/main
  • Squashed commits

@johanseto

johanseto commented Nov 20, 2023

Copy link
Copy Markdown
Contributor Author

@omar-nelc could you take a look 😬

@johanseto
johanseto force-pushed the jlc/add-pkce-openid-backend branch from e29b8ba to 33c6ee0 Compare November 20, 2023 14:20
@johanseto
johanseto marked this pull request as ready for review November 20, 2023 14:46
This add a generic backend based in ConfigurableOpenIdConnectAuth but
with PKCE.
This backend is inspired  in the social-core way to implement PKCE.
There is a current PR in working, but for the moment, that class is not merged and accesible.
So after that is finished this has it code for `code_challenge` and `code_challenge_method`implementation.
PR: python-social-auth/social-core#856
@johanseto
johanseto force-pushed the jlc/add-pkce-openid-backend branch from 33c6ee0 to 1584426 Compare November 20, 2023 14:47

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks @johanv26. I have added a suggestion to refactor the BaseOAuth2PKCEMixin and use it so we can refactor later and use the BaseOAuth2PKCE base class once it lands on upstream.

This usually helps with the release upgrade.

Comment thread eox_core/social_tpa_backends.py
Comment thread eox_core/social_tpa_backends.py Outdated
johanseto and others added 2 commits November 21, 2023 09:58
Co-authored-by: Omar Al-Ithawi @ NELC <134635705+omar-nelc@users.noreply.github.com>

chore: suggestions from code review

Co-authored-by: Omar Al-Ithawi @ NELC <134635705+omar-nelc@users.noreply.github.com>
@johanseto
johanseto force-pushed the jlc/add-pkce-openid-backend branch from d0a7b2c to 6664e76 Compare November 21, 2023 14:58
Comment thread eox_core/social_tpa_backends.py Outdated
Comment on lines +284 to +286
PKCE_DEFAULT_CODE_CHALLENGE_METHOD = "s256"
PKCE_DEFAULT_CODE_VERIFIER_LENGTH = 32
USE_PKCE = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks @johanv26!! Looks much better now!

Those aren't needed, because they're inherited from the mixin.

@andrey-canon andrey-canon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, I just left some comments related with the code's style that I would have implemented , however I know this is a copy of the social-core pr so feel free to ignore these I just wanted to point them out

Comment thread eox_core/social_tpa_backends.py Outdated
Comment thread eox_core/social_tpa_backends.py
Comment thread eox_core/social_tpa_backends.py Outdated
Comment on lines +231 to +232
code_verifier = self.strategy.session_get(name)
return code_verifier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
code_verifier = self.strategy.session_get(name)
return code_verifier
code_verifier = self.strategy.session_get(name)
return code_verifier

Comment thread eox_core/social_tpa_backends.py Outdated
Comment on lines +240 to +241
return code_challenge
elif method == "plain":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return code_challenge
elif method == "plain":
return code_challenge
if method == "plain":

Comment thread eox_core/social_tpa_backends.py Outdated

PKCE_DEFAULT_CODE_CHALLENGE_METHOD = "s256"
PKCE_DEFAULT_CODE_VERIFIER_LENGTH = 32
USE_PKCE = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand why is this necessary, I mean the obvious answer is because you can disable that behavior on sub-classes, but if I don't want that behavior on sub-classes I could inherit from BaseOAuth2 instead of this one

Comment thread eox_core/social_tpa_backends.py
Comment thread eox_core/social_tpa_backends.py
Comment thread eox_core/social_tpa_backends.py
Comment thread eox_core/social_tpa_backends.py
@johanseto

Copy link
Copy Markdown
Contributor Author

@andrey-canon I updated to the version is approved in social_core. But taking advantage of that PR is not merged yet, I added some of your review to that PR.
python-social-auth/social-core#856 (review)
Maybe they pay attention and would be included in the social_core version.

@johanseto
johanseto force-pushed the jlc/add-pkce-openid-backend branch from 0f5ecbc to 837a4ae Compare November 21, 2023 17:26
Co-authored-by: Andrey Cañon <andrey.canon@edunext.co>
@johanseto
johanseto force-pushed the jlc/add-pkce-openid-backend branch from 837a4ae to 5a4fc33 Compare November 21, 2023 17:28
@johanseto
johanseto merged commit 9190263 into v6.1.0-nelp Nov 21, 2023
andrey-canon added a commit that referenced this pull request Mar 5, 2024
* feat: add pkce-openid-backend

This adds a generic backend based on ConfigurableOpenIdConnectAuth but
with PKCE.
This backend is inspired in the social-core way to implement PKCE.
There is a current PR in work, but for the moment, that class is not merged and accessible.
So after that is finished this has it code for `code_challenge` and `code_challenge_method`implementation.
PR: python-social-auth/social-core#856

* refactor: avoid repeated pkce conf definition

* feat: update with small changes social_core

* refactor: suggestions from code review

Co-authored-by: Omar Al-Ithawi @ NELC <134635705+omar-nelc@users.noreply.github.com>
Co-authored-by: Andrey Cañon <andrey.canon@edunext.co>
andrey-canon added a commit that referenced this pull request Mar 5, 2024
This was referenced Nov 26, 2025
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.

2 participants