-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Identity] Support for tenant Id Challenges / tenant discovery in ClientCredentials #15837
Conversation
…scovery in ClientCredentials
This comment has been minimized.
This comment has been minimized.
@@ -314,7 +327,7 @@ export interface UsernamePasswordCredentialOptions extends TokenCredentialOption | |||
// @public | |||
export class VisualStudioCodeCredential implements TokenCredential { | |||
constructor(options?: VisualStudioCodeCredentialOptions); | |||
getToken(scopes: string | string[], _options?: GetTokenOptions): Promise<AccessToken>; | |||
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>; |
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.
Is this a breaking change? Can callers specify the argument name explicitly?
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 is not a breaking change, just a name change :)
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.
Callers can’t specify the argument names like this, they just pass the value.
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.
thankfully we don't have magical kwargs :)
Co-authored-by: Scott Schaab <sschaab@microsoft.com>
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, thanks for the quick turnaround! Please get an approver from the JS team as well.
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 have a couple of questions in the comments, but LGTM from an API/JS/TS perspective.
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.
The public surface changes look good!
I have some remarks about the implementation
@@ -314,7 +327,7 @@ export interface UsernamePasswordCredentialOptions extends TokenCredentialOption | |||
// @public | |||
export class VisualStudioCodeCredential implements TokenCredential { | |||
constructor(options?: VisualStudioCodeCredentialOptions); | |||
getToken(scopes: string | string[], _options?: GetTokenOptions): Promise<AccessToken>; | |||
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>; |
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.
thankfully we don't have magical kwargs :)
Co-authored-by: chradek <51000525+chradek@users.noreply.github.com>
sdk/identity/identity/src/credentials/authorizationCodeCredential.ts
Outdated
Show resolved
Hide resolved
const tenantId = processMultiTenantRequest( | ||
this.tenantId, | ||
this.allowMultiTenantAuthentication, | ||
options | ||
)!; |
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 see you're using the non-null assertion. When would processMultiTenantRequest
return undefined
where that would be ok? We've been bitten by the non-null assertion in other packages and I wonder if it makes more sense to throw an error instead, or at least handle the undefined case.
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.
The tenantId has a default for this credential, which is common
. It’s set on the credential options. processMultiTenantRequest will only pick the getToken options’ tenant if it exists, so either it exists in the options, or is assigned by the user, or is just common
. Would a comment help?
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.
Oh I see. I can throw an error just in case
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 was hoping we could do some TypeScript magic like this:
export function processMultiTenantRequest<T extends string | undefined>(
tenantId: T,
allowMultiTenantAuthentication?: boolean,
getTokenOptions?: GetTokenOptions
): T extends string ? string : string | undefined {
if (
!allowMultiTenantAuthentication &&
getTokenOptions?.tenantId &&
tenantId &&
getTokenOptions.tenantId !== tenantId
) {
throw new Error(multiTenantErrorMessage);
}
if (allowMultiTenantAuthentication && getTokenOptions?.tenantId) {
return getTokenOptions.tenantId;
}
return tenantId as any;
}
That works but I had to resort to casting the final return as any
.
Anyway, it looks like you're really only doing non-null assertion here, I see now your other calls handle undefined. With that said, maybe just add a comment so someone running across it will know this.tenantId
is always available here.
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.
ok I’ll add 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.
Oh look, I can do this!
const tenantId = processMultiTenantRequest(
this.tenantId,
this.allowMultiTenantAuthentication,
options
) || this.tenantId;
Safer ^_^
Hello @sadasant! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Add swagger for Compute Diagnostic Resource Provider (Azure#15837)
This PR adds
tenantId
to thegetTokenOptions
, and adds options on every Identity credential to allow multi-tenant authentication (which will be disabled by default).Fixes #15797