我有一个 React 应用程序,托管在“https://[email protected]”的位置,重定向 URL 为“https://[email protected]/redirect.html”,它设置将 reply_to URl 作为 Azure AD(单页应用程序)配置的状态。这也是为了涵盖来自其他域的呼叫。
MSAL 版本:
"@azure/msal-browser": "^2.33.0"
现在,我也想在 Azure DevOps(ADO) 扩展的 iFrame 中呈现此页面,为此我正在发送和接收一些带有令牌请求和响应的消息,以在呈现 React 应用程序的 ADO 的 iFrame 和独立的用户界面。因此,无论何时从 ADO 扩展中加载 UI,我们都会获取 ADO 帐户信息,并使用 MSAL 库获取令牌。这就是我们正在做的事情:
const msalConfig: Configuration = {
auth: aadConfig,
cache: {
cacheLocation: "localStorage"
}
}
const msal = new PublicClientApplication(msalConfig);
public async acquireToken(resourceId: string): Promise<string> {
await this.msal.handleRedirectPromise(); // Getting the error here
const loginRequest = {
scopes: [resourceId + "/.default"],
redirectUri: "https://[email protected]/redirect.html", // This is what exactly mentioned in AAD App registration as well, and works for standalone
authority: getAuthority(),
state: config.getReplyToURL() // This is being set in the redirect.html and is the extension URL in ADO, and this is being passed on to ADO iframe
};
const account = this.msal.getActiveAccount();
if (!account) {
await this.msal.loginRedirect(loginRequest);
this.msal.setActiveAccount(this.msal.getAllAccounts()[0]);
}
const accessTokenRequest = {
scopes: [resourceId + "/.default"],
account: account || this.msal.getActiveAccount(),
authority: getAuthority()
};
try {
return await this.msal.acquireTokenSilent(accessTokenRequest);
} catch (error) {
// Handle Error
}
}
但是,我在这一行中收到以下错误:
等待 this.msal.handleRedirectPromise()
Uncaught (in promise) Error: Error: authorization_code_missing_from_server_response: Server response does not contain an authorization code to proceed.
有人可以帮助我正确地了解这个问题到底是什么吗?试图在 MSAL 错误文档中查找,但无法具体找到任何内容。该错误表明没有响应返回代码,但是同一组 aad 配置对于独立的 [email protected] 工作正常,那么当我尝试在 iFrame 中呈现它时发生了什么?