-
Notifications
You must be signed in to change notification settings - Fork 291
Custom ODataUriParser extension to cast token claim values as database column value type #895
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jarupatj
suggested changes
Oct 20, 2022
…troduced EDM Model builder handling of Guid types.
Contributor
Author
|
Added tests. |
jarupatj
approved these changes
Oct 21, 2022
…URL query string processing.
Aniruddh25
reviewed
Oct 22, 2022
Aniruddh25
reviewed
Oct 22, 2022
Aniruddh25
reviewed
Oct 22, 2022
Aniruddh25
approved these changes
Oct 22, 2022
Collaborator
Aniruddh25
left a comment
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.
LGTM after potentially avoiding reparsing
7 tasks
Aniruddh25
approved these changes
Oct 25, 2022
…com/Azure/data-api-builder into dev/seleonar/policyClaimTypeCasting
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why This Change
Closes #844
When a request reaches the policy processing stage of authorization, the request fails when a mismatch exists between the claim value type present in the access token and the field value type on the database object referenced in an authorization policy.
Example
Given the database authorization policy:
Given the access token payload where the claim 'SeriesId' has a value type of string:
{ "claims": [{ "typ": "SeriesId", "val": "10000" }] }and given the database object field's value type referenced by the policy text
@item.series_idis integer.A HTTP 400 Bad Request error is return with the message
A binary operator with incompatible types was detected. Found operand types 'Edm.String' and 'Edm.Int32' for operator kind 'Equal'.What is this change?
For authorization policy processing only, this change introduces a custom ODataUriParser extension Microsoft Dev Blog Example which attempts to typecast the value present in the access token claim to the type of the database(EDM model) object field, prior to OData filter parsing. The custom extension attempts to match the database type because the predicate, added to the database query as a result of processing an authorization policy, should utilize the correct value type or the query will fail.
Cases:
token: IsAdmin (bool) => database: IsAdmin (integer)
JSON data types covered in this change via http://json-schema.org/understanding-json-schema/reference/type.html
When a claim fails typecasting to the database field value type, the request will still fail with (tbd which one)
How is this tested?
Sample Request(s)
Modify Authentication config to be Static Web Apps:
Modify Book entity config to contain a new role
In Postman create a GET request for URL:
https://localhost:5001/api/BookSet Headers:
X-MS-CLIENT-PRINCIPAL:
X-MS-API-ROLE: swa-claims-valuetype
Expected Result is the following (not HTTP 400) because @claims.pubID is now casted to an int type to match
the value type of @item.publisher_id.
{ "value": [ { "id": 1, "title": "Awesome book", "publisher_id": 1234 }, { "id": 2, "title": "Also Awesome book", "publisher_id": 1234 } ] }