-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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: Validate Azure JWTs using authlib
#2112
fix: Validate Azure JWTs using authlib
#2112
Conversation
authlib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and simple, can you add tests please?
Codecov Report
@@ Coverage Diff @@
## master #2112 +/- ##
==========================================
+ Coverage 78.29% 78.49% +0.19%
==========================================
Files 72 72
Lines 8699 8685 -14
==========================================
+ Hits 6811 6817 +6
+ Misses 1888 1868 -20
Flags with carried forward coverage won't be shown. Click here to find out more.
|
I just added a unittest for the new Is this sufficient as a unit test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good one last comment
requirements.txt
Outdated
@@ -6,6 +6,8 @@ | |||
# | |||
apispec[yaml]==6.3.0 | |||
# via Flask-AppBuilder (setup.py) | |||
authlib==1.2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this to requirements extra?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that authlib
is already in requirements-extra.txt
- now I just upgraded the version there from 0.15.4
to the latest version 1.2.1
It's ok, I'm going to revisit the Azure and claims mapping also, I'll add more tests |
|
||
jwt_decoded_payload = json.loads(decoded_payload.decode("utf-8")) | ||
def _decode_and_validate_azure_jwt(self, id_token): | ||
keyset = JsonWebKey.import_key_set(requests.get(MICROSOFT_KEY_SET_URL).json()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be cached or set at boot time
Thank you @wolfdn ! |
Cool! |
This PR brings all the necessary changes to upgrade to FAB 4.3.9 from 4.3.6. It incorporates those changes: * dpgaspar/Flask-AppBuilder#2112 * dpgaspar/Flask-AppBuilder#2121 It also removes the limitation of the WTForms after compatibility has been implemented: * dpgaspar/Flask-AppBuilder#2138
This PR brings all the necessary changes to upgrade to FAB 4.3.9 from 4.3.6. It incorporates those changes: * dpgaspar/Flask-AppBuilder#2112 * dpgaspar/Flask-AppBuilder#2121 It also removes the limitation of the WTForms after compatibility has been implemented: * dpgaspar/Flask-AppBuilder#2138
This PR brings all the necessary changes to upgrade to FAB 4.3.9 from 4.3.6. It incorporates those changes: * dpgaspar/Flask-AppBuilder#2112 * dpgaspar/Flask-AppBuilder#2121 It also removes the limitation of the WTForms after compatibility has been implemented: * dpgaspar/Flask-AppBuilder#2138 GitOrigin-RevId: 4198146f49b72d051d82fbd821c7105cf2f4a8bd
This PR brings all the necessary changes to upgrade to FAB 4.3.9 from 4.3.6. It incorporates those changes: * dpgaspar/Flask-AppBuilder#2112 * dpgaspar/Flask-AppBuilder#2121 It also removes the limitation of the WTForms after compatibility has been implemented: * dpgaspar/Flask-AppBuilder#2138 GitOrigin-RevId: 4198146f49b72d051d82fbd821c7105cf2f4a8bd
This PR brings all the necessary changes to upgrade to FAB 4.3.9 from 4.3.6. It incorporates those changes: * dpgaspar/Flask-AppBuilder#2112 * dpgaspar/Flask-AppBuilder#2121 It also removes the limitation of the WTForms after compatibility has been implemented: * dpgaspar/Flask-AppBuilder#2138 GitOrigin-RevId: 4198146f49b72d051d82fbd821c7105cf2f4a8bd
Description
This PR introduces authlib to decode and validate JWTs from Azure.
Note: I tried to use
joserfc
instead of authlib - as recommended in the authlib docs - but then realized that joserfc is only compatible with Python >= 3.8. To keep compatibility with Python 3.7 we should use authlib.Until now we were using a custom implementation to parse Azure JWTs. Only the content of JWTs was evaluated, but it was not checked if the signature of the JWT is even valid.
By using
authlib
we can get rid of the custom parsing implementation for Azure JWTs inmanager.py
and it also allows us to validate the claims of the JWT.The public keys from Microsoft are automatically fetched and used to decode the JWT.
Some basic claims of the JWT are also validated (
issued at
,not before
andexpiry
).ADDITIONAL INFORMATION