Skip to content

Commit dd00186

Browse files
author
Adrian Gonzalez-Martin
authored
Update Authlib and pass verify flag downstream (#46)
1 parent e98abc8 commit dd00186

File tree

9 files changed

+40
-32
lines changed

9 files changed

+40
-32
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ You can see an example usage below:
2323

2424
```python
2525
from seldon_deploy_sdk import EnvironmentApi, Configuration, ApiClient
26-
from seldon_deploy_sdk.auth import OIDCAuthenticator
26+
from seldon_deploy_sdk.auth import AuthMethod, OIDCAuthenticator
2727

2828
config = Configuration()
2929
config.host = "http://X.X.X.X/seldon-deploy/api/v1alpha1"
3030
config.oidc_client_id = "sd-api"
3131
config.oidc_client_secret = "sd-api-secret"
3232
config.oidc_server = "http://X.X.X.X/auth/realms/deploy-realm"
33-
config.auth_method = "auth_code"
33+
config.auth_method = AuthMethod.AUTH_CODE
3434

3535
auth = OIDCAuthenticator(config)
3636
config.id_token = auth.authenticate()

python/licenses/license.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Authlib
2-
0.15.5
2+
1.0.1
33
BSD License
44
BSD 3-Clause License
55

python/licenses/license_info.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"Name","Version","License"
2-
"Authlib","0.15.5","BSD License"
2+
"Authlib","1.0.1","BSD License"
33
"certifi","2022.9.24","Mozilla Public License 2.0 (MPL 2.0)"
44
"cffi","1.15.1","MIT License"
55
"cryptography","38.0.1","Apache Software License; BSD License"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
from .base import AuthMethod
12
from .session import SessionAuthenticator
23
from .openid import OIDCAuthenticator
34

4-
__all__ = ["SessionAuthenticator", "OIDCAuthenticator"]
5+
__all__ = ["AuthMethod", "SessionAuthenticator", "OIDCAuthenticator"]

python/seldon_deploy_sdk/auth/openid.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import logging
22
import os
33
import urllib3
4+
import webbrowser
45

56
from typing import Dict
67
from urllib.parse import urlencode
7-
from authlib.integrations.base_client import FrameworkIntegration, RemoteApp
8+
from authlib.integrations.base_client import FrameworkIntegration, OAuth2Mixin
89
from authlib.integrations.requests_client import OAuth2Session
910

1011
from ..configuration import Configuration
@@ -21,10 +22,6 @@
2122
ACCESS_TOKEN_FIELD = "access_token"
2223

2324

24-
class OIDCIntegration(FrameworkIntegration):
25-
oauth2_client_cls = OAuth2Session
26-
27-
2825
def _get_token(token: Dict[str, str]) -> str:
2926
if ID_TOKEN_FIELD not in token:
3027
logger.info(
@@ -43,7 +40,6 @@ def __init__(self, config: Configuration):
4340
super().__init__(config)
4441

4542
if not config.verify_ssl:
46-
os.environ["CURL_CA_BUNDLE"] = ""
4743
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
4844

4945
if config.oidc_server is None:
@@ -64,13 +60,15 @@ def __init__(self, config: Configuration):
6460

6561
server_metadata_url = f"{config.oidc_server}/.well-known/openid-configuration"
6662

67-
self._app = RemoteApp(
68-
framework=OIDCIntegration,
63+
self._app = OAuth2Mixin(
64+
framework=FrameworkIntegration,
65+
client_kwargs={"verify": config.verify_ssl},
6966
client_id=config.oidc_client_id,
7067
client_secret=config.oidc_client_secret,
7168
server_metadata_url=server_metadata_url,
7269
access_token_params=access_token_params,
7370
)
71+
self._app.client_cls = OAuth2Session
7472
self._app.load_server_metadata()
7573

7674
@_soft_deprecate # type: ignore
@@ -109,10 +107,15 @@ def _use_authorization_code(self):
109107
state=self._AuthCodeState,
110108
scope=self._config.scope,
111109
)["url"]
110+
111+
webbrowser.open_new_tab(request_url)
112112
print(
113-
"Please copy the following URL into a browser to log in.",
114-
"You will be redirected and shown a code to copy and paste here.",
115-
f"\n\n\t'{request_url}'\n\n",
113+
"The following URL should have opened now on a new tab, where you "
114+
"will be able to log in.\n"
115+
"If it hasn't, please copy the following URL into a browser.\n"
116+
"Once you have logged in, you will be redirected and will be shown a code "
117+
"to copy and paste below."
118+
f"\n\n\t{request_url}\n\n"
116119
)
117120
response_code = self._get_response_code()
118121
response_code_query = urlencode({"code": response_code})

python/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"python-dateutil>=2.1",
2828
"six>=1.10",
2929
"urllib3>=1.23",
30-
"Authlib<=0.16.0",
30+
"Authlib>=1.0.0,<1.1.0",
3131
]
32-
32+
3333

3434
setup(
3535
name=NAME,

templates/python/auth/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
from .base import AuthMethod
12
from .session import SessionAuthenticator
23
from .openid import OIDCAuthenticator
34

4-
__all__ = ["SessionAuthenticator", "OIDCAuthenticator"]
5+
__all__ = ["AuthMethod", "SessionAuthenticator", "OIDCAuthenticator"]

templates/python/auth/openid.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import logging
22
import os
33
import urllib3
4+
import webbrowser
45

56
from typing import Dict
67
from urllib.parse import urlencode
7-
from authlib.integrations.base_client import FrameworkIntegration, RemoteApp
8+
from authlib.integrations.base_client import FrameworkIntegration, OAuth2Mixin
89
from authlib.integrations.requests_client import OAuth2Session
910

1011
from ..configuration import Configuration
@@ -21,10 +22,6 @@
2122
ACCESS_TOKEN_FIELD = "access_token"
2223

2324

24-
class OIDCIntegration(FrameworkIntegration):
25-
oauth2_client_cls = OAuth2Session
26-
27-
2825
def _get_token(token: Dict[str, str]) -> str:
2926
if ID_TOKEN_FIELD not in token:
3027
logger.info(
@@ -43,7 +40,6 @@ def __init__(self, config: Configuration):
4340
super().__init__(config)
4441

4542
if not config.verify_ssl:
46-
os.environ["CURL_CA_BUNDLE"] = ""
4743
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
4844

4945
if config.oidc_server is None:
@@ -64,13 +60,15 @@ def __init__(self, config: Configuration):
6460

6561
server_metadata_url = f"{config.oidc_server}/.well-known/openid-configuration"
6662

67-
self._app = RemoteApp(
68-
framework=OIDCIntegration,
63+
self._app = OAuth2Mixin(
64+
framework=FrameworkIntegration,
65+
client_kwargs={"verify": config.verify_ssl},
6966
client_id=config.oidc_client_id,
7067
client_secret=config.oidc_client_secret,
7168
server_metadata_url=server_metadata_url,
7269
access_token_params=access_token_params,
7370
)
71+
self._app.client_cls = OAuth2Session
7472
self._app.load_server_metadata()
7573

7674
@_soft_deprecate # type: ignore
@@ -109,10 +107,15 @@ def _use_authorization_code(self):
109107
state=self._AuthCodeState,
110108
scope=self._config.scope,
111109
)["url"]
110+
111+
webbrowser.open_new_tab(request_url)
112112
print(
113-
"Please copy the following URL into a browser to log in.",
114-
"You will be redirected and shown a code to copy and paste here.",
115-
f"\n\n\t'{request_url}'\n\n",
113+
"The following URL should have opened now on a new tab, where you "
114+
"will be able to log in.\n"
115+
"If it hasn't, please copy the following URL into a browser.\n"
116+
"Once you have logged in, you will be redirected and will be shown a code "
117+
"to copy and paste below."
118+
f"\n\n\t{request_url}\n\n"
116119
)
117120
response_code = self._get_response_code()
118121
response_code_query = urlencode({"code": response_code})

templates/python/setup.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ REQUIRES = [
2121
"python-dateutil>=2.1",
2222
"six>=1.10",
2323
"urllib3>=1.23",
24-
"Authlib<=0.16.0",
24+
"Authlib>=1.0.0,<1.1.0",
2525
]
26-
26+
2727
{{#asyncio}}
2828
REQUIRES.append("aiohttp")
2929
{{/asyncio}}

0 commit comments

Comments
 (0)