-
Notifications
You must be signed in to change notification settings - Fork 1
refactor!: generated clients inherit ConnectorClientBase (#88) #90
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
Changes from all commits
85e52ff
4129209
a4e1852
14da73e
6c3053b
f4fd5e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| using global::Azure.Core; | ||
|
|
||
| namespace Microsoft.Azure.Connectors.Sdk.Authentication | ||
| { | ||
| /// <summary> | ||
| /// Adapts an <see cref="TokenCredential"/> (from Azure.Core) to the SDK's | ||
| /// <see cref="ITokenProvider"/> interface, enabling generated clients to accept | ||
| /// any Azure credential (DefaultAzureCredential, ManagedIdentityCredential, etc.). | ||
| /// </summary> | ||
| public class TokenCredentialTokenProvider : ITokenProvider | ||
| { | ||
| private readonly TokenCredential _credential; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="TokenCredentialTokenProvider"/> class. | ||
| /// </summary> | ||
| /// <param name="credential">The Azure credential to wrap.</param> | ||
| public TokenCredentialTokenProvider(TokenCredential credential) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(credential); | ||
| this._credential = credential; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<string> GetAccessTokenAsync(string[] scopes, CancellationToken cancellationToken = default) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General suggestion: I recommend always having This suggestion is speaking with my own .NET experience and preferences, and it is not aligned with the Azure SDK .NET guidelines.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I paid the significant cost of updating thousands of lines of the Azure MCP server code to plumb through |
||
| { | ||
| ArgumentNullException.ThrowIfNull(scopes); | ||
|
|
||
| if (scopes.Length == 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: checking the length, but not the contents of the array. Do we care about null or empty string array elements? |
||
| { | ||
| throw new ArgumentException(message: "At least one scope must be provided.", paramName: nameof(scopes)); | ||
| } | ||
|
|
||
| var context = new TokenRequestContext(scopes); | ||
| var token = await this._credential | ||
| .GetTokenAsync(context, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why include |
||
|
|
||
| return token.Token; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.