-
Notifications
You must be signed in to change notification settings - Fork 50
Add NativeAuthRequestInterceptor for custom per-request headers and UI Automation, Fixes AB#3600652 #3112
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
Merged
Add NativeAuthRequestInterceptor for custom per-request headers and UI Automation, Fixes AB#3600652 #3112
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2749af0
Add NativeAuthRequestInterceptor for custom per-request headers
spetrescu84 f04517b
Merge origin/dev and resolve changelog conflict
Copilot f450877
Address PR review feedback for interceptor wiring and docs
Copilot d415f28
Add docs and interceptor type guard per review feedback
Copilot 1611df9
Add comprehensive interceptor tests for all interactors
spetrescu84 d98d3e1
Build: publish libraries directly to NewAndroid feed
fadidurah ce8c4e7
Address PR review comments: improve warn message, document overwrite …
spetrescu84 4dd8406
Consolidate duplicated test logic into RequestInterceptorHeaderUtilsTest
spetrescu84 baae279
common4j: don't tie sourcesJar/javadocJar to assemble
fadidurah 46c3b31
Add gradle configure-on-demand for build perf
fadidurah 4343317
Merge branch 'dev' into spetrescu/custom_headers
spetrescu84 bf80e0b
Updated message
spetrescu84 521100e
Updated comment
spetrescu84 d91d6bf
Add symmetric null-interceptor tests for all JIT methods
spetrescu84 89f5860
Use realistic per-method endpoint URLs in interceptor tests
spetrescu84 3371b7e
Merge branch 'dev' into fadi/publish-libraries-to-newandroid-feed
fadidurah 0d1e6fb
Merge branch 'dev' into spetrescu/custom_headers
spetrescu84 d313d38
Fix POM: write current version for project deps to avoid 'unspecified'
fadidurah 28adbb7
Merge branch 'dev' of https://github.com/AzureAD/microsoft-aut status
fadidurah c8cd68b
fix token endpoint parsing
fadidurah 62b6e05
Move NativeAuthRequestInterceptor to MSAL module
spetrescu84 2dc5782
Merge branch 'dev' into spetrescu/custom_headers
spetrescu84 7a812bf
Merge branch 'dev' into fadi/publish-libraries-to-newandroid-feed
fadidurah f005147
Revert "Build: publish libraries directly to NewAndroid feed"
fadidurah 7a4b22b
Add Native Auth to installed apps
spetrescu84 62520d6
Merge branch 'dev' into spetrescu/custom_headers
spetrescu84 ba9f604
Merge branch 'dev' into spetrescu/custom_headers
spetrescu84 a6bf2df
Merge commit f005147 (fadi/publish-libraries-to-newandroid-feed rever…
spetrescu84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
77 changes: 77 additions & 0 deletions
77
...main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthHeaderValidator.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // All rights reserved. | ||
| // | ||
| // This code is licensed under the MIT License. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files(the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions : | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| package com.microsoft.identity.common.java.nativeauth.providers | ||
|
|
||
| import com.microsoft.identity.common.java.logging.Logger | ||
|
|
||
| /** | ||
| * Validates custom headers provided by an [OAuth2RequestInterceptor]. | ||
| * Enforces that header names start with "x-" and do not use reserved prefixes. | ||
| */ | ||
| object NativeAuthHeaderValidator { | ||
|
|
||
| private val TAG = NativeAuthHeaderValidator::class.java.simpleName | ||
|
|
||
| private val RESERVED_PREFIXES = listOf("x-ms-", "x-client-", "x-broker-", "x-app-") | ||
|
|
||
| /** | ||
| * Filters a map of headers, returning only those that are valid per the interceptor contract. | ||
| * Invalid headers are logged as warnings and excluded from the result. | ||
| * | ||
| * @param headers The raw headers provided by the interceptor. | ||
| * @return A map containing only valid headers using lowercase field names, or an empty map if none are valid. | ||
| */ | ||
| fun filterValidHeaders(headers: Map<String, String>): Map<String, String> { | ||
| val validHeaders = mutableMapOf<String, String>() | ||
|
|
||
| for ((field, value) in headers) { | ||
| val lowerField = field.lowercase() | ||
|
|
||
| if (!lowerField.startsWith("x-")) { | ||
| Logger.warn( | ||
| TAG, | ||
| "Additional header field \"$field\" must start with the \"x-\" prefix. Ignoring." | ||
| ) | ||
| continue | ||
| } | ||
|
|
||
| var isReserved = false | ||
| for (reserved in RESERVED_PREFIXES) { | ||
| if (lowerField.startsWith(reserved)) { | ||
| Logger.warn( | ||
| TAG, | ||
| "Additional header field \"$field\" uses reserved prefix \"$reserved\". Ignoring." | ||
| ) | ||
| isReserved = true | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if (!isReserved) { | ||
| validHeaders[lowerField] = value | ||
| } | ||
| } | ||
|
|
||
| return validHeaders | ||
| } | ||
| } | ||
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
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
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
65 changes: 65 additions & 0 deletions
65
...ft/identity/common/java/nativeauth/providers/interactors/RequestInterceptorHeaderUtils.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // All rights reserved. | ||
| // | ||
| // This code is licensed under the MIT License. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files(the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions : | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| package com.microsoft.identity.common.java.nativeauth.providers.interactors | ||
|
|
||
| import com.microsoft.identity.common.java.nativeauth.providers.NativeAuthHeaderValidator | ||
| import com.microsoft.identity.common.java.providers.oauth2.OAuth2RequestInterceptor | ||
| import java.net.URL | ||
|
|
||
| /** | ||
| * Applies additional interceptor headers to the base request headers for native auth interactors. | ||
| * | ||
| * Interceptor headers replace matching base headers regardless of casing. Interceptor headers are | ||
| * first validated and normalized to lowercase by [NativeAuthHeaderValidator], which filters out | ||
| * any non-`x-` prefixed headers and reserved prefixes (`x-ms-`, `x-client-`, `x-broker-`, `x-app-`). | ||
| * This ensures that mandatory SDK headers (e.g., `Content-Type`, `x-client-SKU`) cannot be | ||
| * overwritten by the interceptor, since they either lack the `x-` prefix or use a reserved prefix. | ||
| * | ||
| * @param requestUrl The outbound request URL. | ||
| * @param headers The base request headers. | ||
| * @param requestInterceptor Optional interceptor providing additional headers. | ||
| * @return The merged headers map with interceptor values taking precedence for valid custom headers. | ||
| */ | ||
| internal fun applyInterceptorHeaders( | ||
| requestUrl: URL, | ||
| headers: Map<String, String?>, | ||
| requestInterceptor: OAuth2RequestInterceptor? | ||
| ): Map<String, String?> { | ||
| if (requestInterceptor == null) return headers | ||
|
|
||
| val additionalHeaders = requestInterceptor.additionalHeaders(requestUrl) ?: return headers | ||
| // For case-insensitive merge, the headers in RESERVED_PREFIXES are filtered out | ||
| val validHeaders = NativeAuthHeaderValidator.filterValidHeaders(additionalHeaders) | ||
| if (validHeaders.isEmpty()) return headers | ||
|
|
||
| val mergedHeaders = headers.toMutableMap() | ||
| for ((field, value) in validHeaders) { | ||
| val existingHeader = mergedHeaders.keys.firstOrNull { it.equals(field, ignoreCase = true) } | ||
| if (existingHeader != null) { | ||
| mergedHeaders.remove(existingHeader) | ||
|
mustafamizrak marked this conversation as resolved.
|
||
| } | ||
| mergedHeaders[field] = value | ||
|
mustafamizrak marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return mergedHeaders | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.