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 #333 #334

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 20 additions & 7 deletions httpx_oauth/clients/openid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple, get_args

import httpx

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2RequestError
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2ClientAuthMethod, OAuth2RequestError

BASE_SCOPES = ["openid", "email"]

Expand Down Expand Up @@ -70,6 +70,19 @@ def __init__(
"revocation_endpoint_auth_methods_supported", ["client_secret_basic"]
)

supported_auth_methods = get_args(OAuth2ClientAuthMethod)
# check if there is any supported and select the first one
Copy link
Owner

Choose a reason for hiding this comment

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

That's clever 👍

token_endpoint_auth_methods_supported = [
method
for method in token_endpoint_auth_methods_supported
if method in supported_auth_methods
]
revocation_endpoint_auth_methods_supported = [
method
for method in revocation_endpoint_auth_methods_supported
if method in supported_auth_methods
]

super().__init__(
client_id,
client_secret,
Expand All @@ -80,11 +93,11 @@ def __init__(
name=name,
base_scopes=base_scopes,
token_endpoint_auth_method=token_endpoint_auth_methods_supported[0],
revocation_endpoint_auth_method=revocation_endpoint_auth_methods_supported[
0
]
if revocation_endpoint
else None,
revocation_endpoint_auth_method=(
revocation_endpoint_auth_methods_supported[0]
if revocation_endpoint
else None
),
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clients_facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def test_get_long_lived_access_token(self, load_mock, get_respx_call_args)
assert f"client_id={CLIENT_ID}" in content
assert f"client_secret={CLIENT_SECRET}" in content

assert type(access_token) == OAuth2Token
assert type(access_token) is OAuth2Token
assert "access_token" in access_token
assert "token_type" in access_token
assert access_token.is_expired() is False
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clients_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def test_refresh_token(self, load_mock, get_respx_call_args):
assert "client_id=CLIENT_ID" in content
assert "client_secret=CLIENT_SECRET" in content

assert type(access_token) == OAuth2Token
assert type(access_token) is OAuth2Token
assert "access_token" in access_token
assert "token_type" in access_token
assert access_token.is_expired() is False
Expand Down
4 changes: 2 additions & 2 deletions tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async def test_get_access_token(
assert f"client_id={CLIENT_ID}" in content
assert f"client_secret={CLIENT_SECRET}" in content

assert type(access_token) == OAuth2Token
assert type(access_token) is OAuth2Token
assert "access_token" in access_token
assert "token_type" in access_token
assert access_token.is_expired() is False
Expand Down Expand Up @@ -245,7 +245,7 @@ async def test_refresh_token(
assert f"client_id={CLIENT_ID}" in content
assert f"client_secret={CLIENT_SECRET}" in content

assert type(access_token) == OAuth2Token
assert type(access_token) is OAuth2Token
assert "access_token" in access_token
assert "token_type" in access_token
assert access_token.is_expired() is False
Expand Down
Loading