Add ability to set auth scopes via request options#23
Merged
rickykaare merged 2 commits intomainfrom Jun 10, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds support for multiple authentication scopes via request options
- Converts
GetScopeAPIs toGetScopesreturningstring[]and updates generator, handler, builder, and sample code accordingly - Introduces
HttpRequestMessageExtensionsto set/get per-request scopes - Updates all related tests to pass and verify scope arrays instead of single
TokenRequestContext
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.Implementation.g.verified.cs | Update generator test to use GetScopes and pass scope array to handler |
| test/Cabazure.Client.Runtime.Tests/Builder/HttpClientBuilderExtensionsTests.cs | Rename test to use scopes and replace TokenRequestContext with string[] |
| test/Cabazure.Client.Runtime.Tests/Authentication/BearerTokenProviderTests.cs | Update tests to call GetTokenAsync(string[] scopes, token) |
| test/Cabazure.Client.Runtime.Tests/Authentication/AzureAuthenticationHandlerTests.cs | Adjust handler test to expect GetTokenAsync(string[], CancellationToken) |
| src/Cabazure.Client/ClientInitializationGenerator.cs | Replace GetScope/TokenRequestContext calls with GetScopes/string[] |
| src/Cabazure.Client.Runtime/ICabazureAuthClientOptions.cs | Change GetScope() to GetScopes(): string[] |
| src/Cabazure.Client.Runtime/HttpRequestMessageExtensions.cs | Add extensions to store and retrieve string[] scopes on HttpRequestMessage |
| src/Cabazure.Client.Runtime/Builder/HttpClientBuilderExtensions.cs | Modify AddAuthentication overloads to accept scopes arrays |
| src/Cabazure.Client.Runtime/Authentication/IBearerTokenProvider.cs | Update interface to GetTokenAsync(string[] scopes, CancellationToken) |
| src/Cabazure.Client.Runtime/Authentication/BearerTokenProvider.cs | Implement per-scope caching and use string[] scopes for token requests |
| src/Cabazure.Client.Runtime/Authentication/AzureAuthenticationHandler.cs | Read scopes from request or default and pass to GetTokenAsync |
| samples/AzureRest/AzureRest.Client/AzureRestClientOptions.cs | Update sample to implement GetScopes() returning an array |
Comments suppressed due to low confidence (2)
test/Cabazure.Client.Runtime.Tests/Builder/HttpClientBuilderExtensionsTests.cs:36
- [nitpick] The parameter name
contextis misleading for a scopes array. Rename it toscopesto accurately reflect its purpose.
string[] context,
src/Cabazure.Client.Runtime/HttpRequestMessageExtensions.cs:1
- This extension references
HttpRequestMessagebut is missingusing System.Net.Http;, causing a compile error. Add the appropriate using directive.
namespace Cabazure.Client;
src/Cabazure.Client.Runtime/Authentication/BearerTokenProvider.cs
Outdated
Show resolved
Hide resolved
christianhelle
approved these changes
Jun 10, 2025
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
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.
No description provided.