Skip to content

Commit

Permalink
Follow PEP 561 - Distributing and Packaging Type Information (#95)
Browse files Browse the repository at this point in the history
* PEP 561 is followed

* redirect_uris are extended with pydantic.AnyHttpUrl
  • Loading branch information
parfeniukink authored Nov 24, 2023
1 parent 7c84de4 commit 429e83b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Empty file added fastapi_sso/py.typed
Empty file.
25 changes: 13 additions & 12 deletions fastapi_sso/sso/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import warnings
from types import TracebackType
from typing import Any, Dict, List, Optional, Type
from typing import Any, Dict, List, Optional, Type, Union

import httpx
import pydantic
Expand Down Expand Up @@ -58,25 +58,26 @@ class SSOBase:
provider: str = NotImplemented
client_id: str = NotImplemented
client_secret: str = NotImplemented
redirect_uri: Optional[str] = NotImplemented
redirect_uri: Optional[Union[pydantic.AnyHttpUrl, str]] = NotImplemented
scope: List[str] = NotImplemented
additional_headers: Optional[Dict[str, Any]] = None

def __init__(
self,
client_id: str,
client_secret: str,
redirect_uri: Optional[str] = None,
redirect_uri: Optional[Union[pydantic.AnyHttpUrl, str]] = None,
allow_insecure_http: bool = False,
use_state: bool = False,
scope: Optional[List[str]] = None,
):
# pylint: disable=too-many-arguments
self.client_id = client_id
self.client_secret = client_secret
self.redirect_uri = redirect_uri
self.allow_insecure_http = allow_insecure_http
self.client_id: str = client_id
self.client_secret: str = client_secret
self.redirect_uri: Optional[Union[pydantic.AnyHttpUrl, str]] = redirect_uri
self.allow_insecure_http: bool = allow_insecure_http
self._oauth_client: Optional[WebApplicationClient] = None

# TODO: Remove use_state argument and attribute
if use_state:
warnings.warn(
Expand Down Expand Up @@ -197,7 +198,7 @@ async def userinfo_endpoint(self) -> Optional[str]:
async def get_login_url(
self,
*,
redirect_uri: Optional[str] = None,
redirect_uri: Optional[Union[pydantic.AnyHttpUrl, str]] = None,
params: Optional[Dict[str, Any]] = None,
state: Optional[str] = None,
) -> str:
Expand Down Expand Up @@ -332,13 +333,13 @@ async def process_login(
additional_headers = additional_headers or {}
additional_headers.update(self.additional_headers or {})
url = request.url
scheme = url.scheme
if not self.allow_insecure_http and scheme != "https":

if not self.allow_insecure_http and url.scheme != "https":
current_url = str(url).replace("http://", "https://")
scheme = "https"
else:
current_url = str(url)
current_path = f"{scheme}://{url.netloc}{url.path}"

current_path = f"{url.scheme}://{url.netloc}{url.path}"

token_url, headers, body = self.oauth_client.prepare_token_request(
await self.token_endpoint,
Expand Down
6 changes: 4 additions & 2 deletions fastapi_sso/sso/microsoft.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Microsoft SSO Oauth Helper class"""

from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, List, Optional, Union

import pydantic

from fastapi_sso.sso.base import DiscoveryDocument, OpenID, SSOBase

Expand All @@ -20,7 +22,7 @@ def __init__(
self,
client_id: str,
client_secret: str,
redirect_uri: Optional[str] = None,
redirect_uri: Optional[Union[pydantic.AnyHttpUrl, str]] = None,
allow_insecure_http: bool = False,
use_state: bool = False, # TODO: Remove use_state argument
scope: Optional[List[str]] = None,
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-sso"
version = "0.7.3"
version = "0.7.4"
description = "FastAPI plugin to enable SSO to most common providers (such as Facebook login, Google login and login via Microsoft Office 365 Account)"
authors = ["Tomas Votava <[email protected]>"]
readme = "README.md"
Expand All @@ -9,6 +9,7 @@ repository = "https://github.com/tomasvotava/fastapi-sso"
homepage = "https://tomasvotava.github.io/fastapi-sso/"
documentation = "https://tomasvotava.github.io/fastapi-sso/"
keywords = ["fastapi", "sso", "oauth", "google", "facebook", "spotify"]
include = ["fastapi_sso/py.typed"]

[tool.pytest.ini_options]
testpaths = ["tests/"]
Expand Down

0 comments on commit 429e83b

Please sign in to comment.