![](/img/trans.png)
[英]How to register an application in Azure AD for my tenants using CSP Global Admin credentials?
[英]How to allow users from only some specific tenants to be able to login to my app using Azure AD
我正在使用AngularJs并使用Azure AD进行身份验证来构建SPA。 我的应用是多租户。
但是,我可以看到Azure AD允许来自任何Active Directory的任何租户的用户登录到我的应用程序。
他们仅获得一个同意屏幕(成功登录后),询问他们是否愿意提供从应用程序访问其信息的权限, 如果单击“是” ,则可以自由重定向到我的应用程序的主页(如果他们拥有我应用的回调网址)。
我尝试修改应用程序的清单文件,并将一些租户添加到knownClientApplications
属性,以仅允许该租户的用户使用,但无济于事。
AngularJs配置代码为:
adalProvider.init(
{
instance: AZURE_AD_INSTANCE,
tenant: 'common',
clientId: AZURE_AD_CLIENT_ID,
extraQueryParameter: 'nux=1',
//cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
}, $httpProvider);
其中,AZURE_AD_INSTANCE和AZURE_AD_CLIENT_ID分别是登录URL和应用程序的客户端ID。
我该怎么做才能只允许特定租户的用户禁止其他租户?
要仅为多租户应用程序启用特定租户,我们需要自己验证租户。
这是供您参考的代码(adal-angular.js):
AdalModule.provider('adalAuthenticationService', function () {
...
var updateDataFromCache = function (resource) {
// only cache lookup here to not interrupt with events
var token = _adal.getCachedToken(resource);
// _oauthData.isAuthenticated = token !== null && token.length > 0;
_oauthData.isAuthenticated = isAuthenticated(token);
var user = _adal.getCachedUser() || { userName: '' };
_oauthData.userName = user.userName;
_oauthData.profile = user.profile;
_oauthData.loginError = _adal.getLoginError();
};
function isAuthenticated(token) {
console.log(token);
if (token !== null && token.length > 0) {
var decodedToken = _adal._extractIdToken(token);
var tenantIds = ["04e14a2c-0e9b-42f8-8b22-3c4a2f1d8802", "04e14a2c-0e9b-42f8-8b22-3c4a2f1d8801"];
var validateTenant = tenantIds.indexOf(decodedToken.tid) !== -1;
return tenantIds.indexOf(decodedToken.tid) !== -1;
} else
return false;
}
为了使用户能够在输入错误的租户帐户后启用登录功能,我们可以自定义登录方法以附加prompt=login
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.