Skip to content

Commit 1cf2cd7

Browse files
authored
feat(authz): Add PKCE support (#55)
* Instruct authlib to use PKCE via OAuth app setup * Use generated code verifier in code-token exchange * Update authlib version in requirements to match setup.py * Regenerate Python client from templates * Update license I'm not sure if this is a meaningful set of changes, or merely an artifact of using a different version of Python (3.10.9).
1 parent f2986fe commit 1cf2cd7

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

python/licenses/license.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ documentation is licensed as follows:
9090

9191

9292
charset-normalizer
93-
3.0.1
93+
3.1.0
9494
MIT License
9595
MIT License
9696

@@ -115,7 +115,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
115115
SOFTWARE.
116116

117117
cryptography
118-
39.0.0
118+
40.0.1
119119
Apache Software License; BSD License
120120
This software is made available under the terms of *either* of the licenses
121121
found in LICENSE.APACHE or LICENSE.BSD. Contributions to cryptography are made
@@ -458,7 +458,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
458458

459459

460460
urllib3
461-
1.26.14
461+
1.26.15
462462
MIT License
463463
MIT License
464464

python/licenses/license_info.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"Authlib","1.0.1","BSD License"
33
"certifi","2022.12.7","Mozilla Public License 2.0 (MPL 2.0)"
44
"cffi","1.15.1","MIT License"
5-
"charset-normalizer","3.0.1","MIT License"
6-
"cryptography","39.0.0","Apache Software License; BSD License"
5+
"charset-normalizer","3.1.0","MIT License"
6+
"cryptography","40.0.1","Apache Software License; BSD License"
77
"idna","3.4","BSD License"
88
"pycparser","2.21","BSD License"
99
"python-dateutil","2.8.2","Apache Software License; BSD License"
1010
"requests","2.28.2","Apache Software License"
1111
"seldon-deploy-sdk","2.0.1","UNKNOWN"
1212
"six","1.16.0","MIT License"
13-
"urllib3","1.26.14","MIT License"
13+
"urllib3","1.26.15","MIT License"

python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
authlib <= 0.16.0
1+
authlib >= 1.0.0,<1.1.0
22
certifi >= 14.05.14
33
python_dateutil >= 2.5.3
44
requests >= 2.0.0, <= 3.0.0

python/seldon_deploy_sdk/auth/openid.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def __init__(self, config: Configuration):
6464

6565
self._app = OAuth2Mixin(
6666
framework=FrameworkIntegration,
67-
client_kwargs={"verify": config.verify_ssl},
67+
client_kwargs={
68+
"verify": config.verify_ssl,
69+
"code_challenge_method": "S256",
70+
},
6871
client_id=config.oidc_client_id,
6972
client_secret=config.oidc_client_secret,
7073
server_metadata_url=server_metadata_url,
@@ -105,11 +108,13 @@ def _use_client_credentials(self):
105108
def _use_authorization_code(self):
106109
deploy_callback_url = f"{self._host}/seldon-deploy/auth/callback"
107110

108-
request_url = self._app.create_authorization_url(
111+
auth_code_request = self._app.create_authorization_url(
109112
redirect_uri=deploy_callback_url,
110113
state=self._AuthCodeState,
111114
scope=self._config.scope,
112-
)["url"]
115+
)
116+
request_url = auth_code_request["url"]
117+
code_verifier = auth_code_request["code_verifier"]
113118

114119
webbrowser.open_new_tab(request_url)
115120
print(
@@ -128,6 +133,7 @@ def _use_authorization_code(self):
128133
authorization_response=response_url,
129134
redirect_uri=deploy_callback_url,
130135
scope=self._config.scope,
136+
code_verifier=code_verifier,
131137
)
132138

133139
return _get_token(token)

templates/python/auth/openid.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def __init__(self, config: Configuration):
6464

6565
self._app = OAuth2Mixin(
6666
framework=FrameworkIntegration,
67-
client_kwargs={"verify": config.verify_ssl},
67+
client_kwargs={
68+
"verify": config.verify_ssl,
69+
"code_challenge_method": "S256",
70+
},
6871
client_id=config.oidc_client_id,
6972
client_secret=config.oidc_client_secret,
7073
server_metadata_url=server_metadata_url,
@@ -105,11 +108,13 @@ def _use_client_credentials(self):
105108
def _use_authorization_code(self):
106109
deploy_callback_url = f"{self._host}/seldon-deploy/auth/callback"
107110

108-
request_url = self._app.create_authorization_url(
111+
auth_code_request = self._app.create_authorization_url(
109112
redirect_uri=deploy_callback_url,
110113
state=self._AuthCodeState,
111114
scope=self._config.scope,
112-
)["url"]
115+
)
116+
request_url = auth_code_request["url"]
117+
code_verifier = auth_code_request["code_verifier"]
113118

114119
webbrowser.open_new_tab(request_url)
115120
print(
@@ -128,6 +133,7 @@ def _use_authorization_code(self):
128133
authorization_response=response_url,
129134
redirect_uri=deploy_callback_url,
130135
scope=self._config.scope,
136+
code_verifier=code_verifier,
131137
)
132138

133139
return _get_token(token)

templates/python/requirements.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
authlib <= 0.16.0
1+
authlib >= 1.0.0,<1.1.0
22
certifi >= 14.05.14
33
python_dateutil >= 2.5.3
44
requests >= 2.0.0, <= 3.0.0

0 commit comments

Comments
 (0)