-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Identity] Removed allowMultiTenantAuthentication (#17915)
* [Identity] Removed allowMultiTenantAuthentication * small changelog improvement * review file * adfs error message
- Loading branch information
Showing
13 changed files
with
112 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
29 changes: 29 additions & 0 deletions
29
sdk/identity/identity/src/util/validateMultiTenant.browser.ts
This file contains 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,29 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { GetTokenOptions } from "@azure/core-auth"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const multiTenantADFSErrorMessage = | ||
"A new tenant Id can't be assigned through the GetTokenOptions when a credential has been originally configured to use the tenant `adfs`."; | ||
|
||
/** | ||
* Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication, | ||
* unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js), | ||
* or unless the original tenant Id is `adfs`. | ||
* @internal | ||
*/ | ||
export function processMultiTenantRequest( | ||
tenantId?: string, | ||
getTokenOptions?: GetTokenOptions | ||
): string | undefined { | ||
if (!getTokenOptions?.tenantId) { | ||
return tenantId; | ||
} | ||
if (tenantId === "adfs") { | ||
throw new Error(multiTenantADFSErrorMessage); | ||
} | ||
return getTokenOptions?.tenantId; | ||
} |
This file contains 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 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,40 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { assert } from "chai"; | ||
import { | ||
multiTenantDisabledErrorMessage, | ||
processMultiTenantRequest | ||
} from "../../../src/util/validateMultiTenant"; | ||
|
||
describe("Identity utilities (Node.js only)", function() { | ||
describe("validateMultiTenantRequest (Node.js only)", function() { | ||
afterEach(() => { | ||
delete process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH; | ||
}); | ||
|
||
it("returns the original tenant and doesn't throw if getTokenOptions does not have a tenantId, even if AZURE_IDENTITY_DISABLE_MULTITENANTAUTH is defined", async function() { | ||
process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH = "true"; | ||
const originalTenant = "credential-options-tenant-id"; | ||
const resultingTenant = processMultiTenantRequest(originalTenant); | ||
assert.equal(resultingTenant, originalTenant); | ||
}); | ||
|
||
it("throws if multi-tenant authentication is disabled via AZURE_IDENTITY_DISABLE_MULTITENANTAUTH", async function() { | ||
let error: Error | undefined; | ||
process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH = "true"; | ||
try { | ||
processMultiTenantRequest("credential-options-tenant-id", { | ||
tenantId: "get-token-options-tenant-id" | ||
}); | ||
} catch (e) { | ||
error = e; | ||
} | ||
assert.ok( | ||
error, | ||
"validateMultiTenantRequest should throw if multi-tenant authentication is disabled" | ||
); | ||
assert.equal(error!.message, multiTenantDisabledErrorMessage); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.