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

feat: add pkce-openid-backend #255

Merged
merged 6 commits into from
Nov 21, 2023
Merged

Conversation

johanseto
Copy link
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
Copy link
Contributor Author

johanseto commented Nov 20, 2023

@omar-nelc could you take a look 😬

@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
Copy link

@omar-nelc omar-nelc left a comment

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.

eox_core/social_tpa_backends.py Show resolved Hide resolved
eox_core/social_tpa_backends.py Outdated Show resolved Hide resolved
johanseto and others added 2 commits November 21, 2023 09:58
Co-authored-by: Omar Al-Ithawi @ NELC <[email protected]>

chore: suggestions from code review

Co-authored-by: Omar Al-Ithawi @ NELC <[email protected]>
Comment on lines 284 to 286
PKCE_DEFAULT_CODE_CHALLENGE_METHOD = "s256"
PKCE_DEFAULT_CODE_VERIFIER_LENGTH = 32
USE_PKCE = True

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.

Copy link
Contributor

@andrey-canon andrey-canon left a comment

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

eox_core/social_tpa_backends.py Outdated Show resolved Hide resolved
eox_core/social_tpa_backends.py Show resolved Hide resolved
eox_core/social_tpa_backends.py Outdated Show resolved Hide resolved
Comment on lines +231 to +232
code_verifier = self.strategy.session_get(name)
return code_verifier
Copy link
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 on lines 240 to 241
return code_challenge
elif method == "plain":
Copy link
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":


PKCE_DEFAULT_CODE_CHALLENGE_METHOD = "s256"
PKCE_DEFAULT_CODE_VERIFIER_LENGTH = 32
USE_PKCE = True
Copy link
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

eox_core/social_tpa_backends.py Show resolved Hide resolved
eox_core/social_tpa_backends.py Show resolved Hide resolved
eox_core/social_tpa_backends.py Show resolved Hide resolved
eox_core/social_tpa_backends.py Show resolved Hide resolved
@johanseto
Copy link
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 merged commit 9190263 into v6.1.0-nelp Nov 21, 2023
1 check passed
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 <[email protected]>
Co-authored-by: Andrey Cañon <[email protected]>
andrey-canon added a commit that referenced this pull request Mar 5, 2024
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