Azure active directory 带有外部API的Adal.js错误AADSTS65001
我有一个Web API项目。根据以下代码针对Azure AD进行身份验证:Azure active directory 带有外部API的Adal.js错误AADSTS65001,azure-active-directory,adal.js,Azure Active Directory,Adal.js,我有一个Web API项目。根据以下代码针对Azure AD进行身份验证: string tenant = "[tenant]"; string audience = "https://[tenant]/MyApp.Backend"; app.UseWindowsAzureActiveDirectoryBearerAuthentication( new WindowsAzureActiveDirectoryBearerAuthenticationOptions { Tenant
string tenant = "[tenant]";
string audience = "https://[tenant]/MyApp.Backend";
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = tenant,
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = audience
}
});
以下是Azure AD中应用程序注册的属性:
- 名称:MyApp.Backend
- 应用程序类型:Web应用程序/API
- 应用程序ID:03486f5a-
- URI:
- oauth2AllowImplicitFlow:false
- 名称:MyApp.Frontend.Console
- 应用程序类型:本机
- 应用程序ID:505f3928-
- oauth2AllowImplicitFlow:false
- 委托权限:(MyAppBackend |访问MyApp.Backend)
var ctx = new AuthenticationContext("https://login.windows.net/[tenant]/");
AuthenticationResult result = ctx.AcquireTokenAsync(
"https://[tenant]/MyApp.Backend",
"505f3928-...",
new Uri("https://[tenant]/MyApp.Frontend.Console"),
new PlatformParameters(PromptBehavior.RefreshSession)).GetAwaiter().GetResult();
问题从水疗开始。以下应用注册描述了该应用:
- 名称:MyApp.Frontend.Web
- 应用程序类型:Web应用程序/API
- 应用程序ID:ea939554-
- URI:
- oauth2AllowImplicitFlow:true
- 委托权限:(MyAppBackend |访问MyApp.Backend),(Microsoft Graph |读取用户文件)
window.config = {
instance: 'https://login.microsoftonline.com/',
tenant: '[tenant]',
clientId: 'ea939554-...',
postLogoutRedirectUri: window.location.origin,
cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
};
let authContext = new AuthenticationContext(config);
let isCallback = authContext.isCallback(window.location.hash);
if (isCallback) {
authContext.handleWindowCallback();
}
let loginError = authContext.getLoginError();
if (isCallback && !loginError) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
} else {
console.log('login error:', loginError);
}
loginButton.onclick = function () {
authContext.login();
};
logoutButton.onclick = function () {
authContext.logOut();
};
actionButton.onclick = function () {
authContext.acquireToken('https://[tenant]/MyApp.Backend', function (error, token) {
// this results in error AADSTS65001
});
};
将不会提取令牌,操作将导致错误AADSTS65001:用户或管理员未同意使用ID为“ea939554-…”的应用程序。为此用户和资源发送交互式授权请求。
如果我尝试获取Microsoft Graph的令牌,则没有错误。将使用有效令牌调用回调。因此SPA的应用程序注册是正确的。错误/错误配置必须在MyApp.Backend注册中的某个地方,但我不知道在哪里。我尝试将后端清单中的隐式流设置为true,并将插入的web前端作为后端清单中的knownClientApplications。但这一切都会导致同样的错误
谁能帮助我?您在收到此问题时是否输入过用户名/密码?我试图通过遵循上面的步骤重现这个问题,但是失败了。直接使用like
发送HTTP请求是否有帮助https://login.microsoftonline.com/{tenant}/oauth2/authorize?response_type=token&client_id={ea939554-…}&redirect_uri={redirectURI}&resource={https://[tenant]/MyApp.Backend}
?@Fei Xue这有点帮助。正如错误消息告诉我们的,它与同意有关。通过adal.js获取令牌时,不会显示同意屏幕。我已经直接请求了URL,并且能够同意。之后,adal.js能够获得MyApp.Backend的令牌。这在不同的会话中起作用,并清除了本地存储。每当新用户第一次获得令牌时,就会导致错误,直到他直接同意为止。现在的问题是为什么adal.js不能同意?更新问题:authContext.login()让我登录,但从未显示同意屏幕。我已从门户中的“企业应用程序-所有应用程序”中删除了应用程序MyApp.Frontend.Web。警告:这不是应用程序注册!现在,每个用户在第一次authContext.login()时都必须接受同意屏幕。我已经建立了一个MyApp.Frontend.Web.Two应用程序注册。它可以工作,无需删除应用程序对象。问题消失了。奇怪。当您收到此问题时,是否输入过用户名/密码?我试图通过遵循上面的步骤重现这个问题,但是失败了。直接使用like发送HTTP请求是否有帮助https://login.microsoftonline.com/{tenant}/oauth2/authorize?response_type=token&client_id={ea939554-…}&redirect_uri={redirectURI}&resource={https://[tenant]/MyApp.Backend}
?@Fei Xue这有点帮助。正如错误消息告诉我们的,它与同意有关。通过adal.js获取令牌时,不会显示同意屏幕。我已经直接请求了URL,并且能够同意。之后,adal.js能够获得MyApp.Backend的令牌。这在不同的会话中起作用,并清除了本地存储。每当新用户第一次获得令牌时,就会导致错误,直到他直接同意为止。现在的问题是为什么adal.js不能同意?更新问题:authContext.login()让我登录,但从未显示同意屏幕。我已从门户中的“企业应用程序-所有应用程序”中删除了应用程序MyApp.Frontend.Web。警告:这不是应用程序注册!现在,每个用户在第一次authContext.login()时都必须接受同意屏幕。我已经建立了一个MyApp.Frontend.Web.Two应用程序注册。它可以工作,无需删除应用程序对象。问题消失了。奇怪。