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

Fix missing PKCE field #321

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 2 additions & 0 deletions docs/oauth2.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Returns the authorization URL where you should redirect the user to ask for thei
* `redirect_uri: str`: Your callback URI where the user will be redirected after the service prompt.
* `state: str = None`: Optional string that will be returned back in the callback parameters to allow you to retrieve state information.
* `scope: Optional[List[str]] = None`: Optional list of scopes to ask for.
* `code_challenge: Optional[str] = None`: Optional code_challenge in a [PKCE context](https://datatracker.ietf.org/doc/html/rfc7636).
* `code_challenge_method: ptional[str] = None`: Optional code_challenge_method in a [PKCE context](https://datatracker.ietf.org/doc/html/rfc7636).
Copy link
Owner

Choose a reason for hiding this comment

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

typo: Optional

* `extras_params: Optional[Dict[str, Any]] = None`: Optional dictionary containing parameters specific to the service.

!!! example
Expand Down
2 changes: 1 addition & 1 deletion httpx_oauth/clients/franceconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def get_authorization_url(
_extras_params["nonce"] = secrets.token_urlsafe()

return await super().get_authorization_url(
redirect_uri, state, scope, _extras_params
redirect_uri, state, scope, extras_params=_extras_params
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
Expand Down
8 changes: 8 additions & 0 deletions httpx_oauth/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ async def get_authorization_url(
redirect_uri: str,
state: Optional[str] = None,
scope: Optional[List[str]] = None,
code_challenge: Optional[str] = None,
code_challenge_method: Optional[str] = None,
Copy link
Owner

Choose a reason for hiding this comment

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

Could you we type it as Literal['plain', 'S256']?

extras_params: Optional[T] = None,
) -> str:
params = {
Expand All @@ -116,6 +118,12 @@ async def get_authorization_url(
if _scope is not None:
params["scope"] = " ".join(_scope)

if code_challenge is not None:
params["code_challenge"] = code_challenge

if code_challenge_method is not None:
params["code_challenge_method"] = code_challenge_method

if extras_params is not None:
params = {**params, **extras_params} # type: ignore

Expand Down
10 changes: 10 additions & 0 deletions tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ async def test_get_authorization_url_with_scopes(self):
)
assert "scope=SCOPE1+SCOPE2+SCOPE3" in authorization_url

@pytest.mark.asyncio
async def test_get_authorization_url_with_plain_code_challenge(self):
authorization_url = await client.get_authorization_url(
REDIRECT_URI,
code_challenge="CODE_CHALLENGE",
code_challenge_method="plain",
)
assert "code_challenge=CODE_CHALLENGE" in authorization_url
assert "code_challenge_method=plain" in authorization_url

@pytest.mark.asyncio
async def test_get_authorization_url_with_extras_params(self):
authorization_url = await client.get_authorization_url(
Expand Down
Loading