azure - MSAL - 使用来自不同目录的两个不同的客户端 ID
问题描述
我有一个将由两个不同实体使用的应用程序,每个实体都有自己的 Azure Active Directory。
最初,我使用的代码是:
var msalConfig = {
auth: {
clientId: '<client-id-1>'
authority: "https://login.microsoftonline.com/<tenant-id>"
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
}
};
现在我想要发生的是,我可以放置两个不同的客户端 ID 和租户 ID 吗?
我可以在第一个 AAD 中使用多个租户,但我想将其限制为只有两个租户。我的方法应该是什么?
解决方案
You could try using the Factory
pattern and create a method that will instantiate the clientApplication
for the proper client. For example:
const msalConfigFoo = {
auth: {
clientId: '<client-id-1>'
authority: "https://login.microsoftonline.com/<tenant-id>"
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
}
};
var msalConfigBar = {
auth: {
clientId: '<client-id-2>'
authority: "https://login.microsoftonline.com/<tenant-id>"
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
}
};
function getClientApplication(clientType) {
if (clientType == "foo") {
return new Msal.UserAgentApplication(msalConfigFoo);
} else {
return new Msal.UserAgentApplication(msalConfigBar);
}
}
推荐阅读
- android - 通过更改菜单中的请求 URL 对 JSON 数组进行排序
- c# - .NET webapi 响应慢 | IIS 花费的时间超过了应用程序执行所花费的平均时间
- amazon-web-services - 如何使我的集装箱港口可以在集装箱外进入?ECS-AWS
- makefile - 并非所有变量都在 Makefile 中递归扩展
- npm - 使用 NPM 安装引导程序
- javascript - JSON 表示转换
- html - 为什么我的图标没有显示 CSS/Html?
- go - 数据结构中命名空间和祖先的区别
- r - R:将时间四舍五入到最接近的小时
- python - Python ConfigParser 打印空数组 {}