Azure ad b2c MSAL js,AAD B2C多因素身份验证,400错误请求,请求头太长
MSAL js版本:v0.2.4Azure ad b2c MSAL js,AAD B2C多因素身份验证,400错误请求,请求头太长,azure-ad-b2c,msal.js,multi-factor-authentication,Azure Ad B2c,Msal.js,Multi Factor Authentication,MSAL js版本:v0.2.4 Chrome版本:79.0.3945.88(官方版本)(64位) 从各种帖子中可以了解到,由于cookie堆积,我们看到“400个坏请求-请求头太长”,但这并不是在我所有的开发人员环境中都会发生的。 我想知道,为什么不是本地环境(从VS代码运行),而是部署环境(Azure应用程序服务) 我可以将MSAL包更新到最新版本,但同时以前它在已部署的环境中运行良好,但现在不行,为什么 是否存在与范围错误消息(AADB2C90055)的任何连接,该消息具有“错误请求-请求
Chrome版本:79.0.3945.88(官方版本)(64位)
let userAgentApplication: Msal.UserAgentApplication;
const createAuthorityUrl = (tenantId: string, policy: string) => {
return `https://${tenantId}.b2clogin.com/tfp/${tenantId}.onmicrosoft.com/${policy}`;
};
export const b2cLogin = (config: B2CConfig) => {
const msalAppConfig = {
cacheLocation: 'localStorage',
redirectUri: `${location.protocol}//${location.host}`,
navigateToLoginRequestUrl: false,
storeAuthStateInCookie: true,
validateAuthority: false,
};
const { clientId, tenantId, myb2cSigninPolicy, myb2cPasswordResetPolicy } = config;
return new Promise(resolve => {
let handlingPasswordReset = false;
const app = new Msal.UserAgentApplication(
clientId,
createAuthorityUrl(tenantId, myb2cSigninPolicy),
(errorDesc: string, token: string) => {
if (errorDesc && errorDesc.indexOf('AADB2C90118') > -1) {
// user forgot password
// https://github.com/Azure-Samples/active-directory-b2c-javascript-msal-singlepageapp/issues/9#issuecomment-347556074
handlingPasswordReset = true;
new Msal.UserAgentApplication(
clientId,
createAuthorityUrl(tenantId, myb2cPasswordResetPolicy),
() => null,
msalAppConfig,
).loginRedirect();
}
return resolve(token);
},
msalAppConfig,
);
if (!handlingPasswordReset) {
userAgentApplication = app;
}
// Seems that MSAL's acquireTokenSilent() won't resolve if run within an iframe
if (window.parent !== window) {
return resolve('');
}
if (!userAgentApplication.isCallback(location.hash)) resolve(getAccessToken());
});
};
export const getAccessToken = async (): Promise<string> => {
if (!userAgentApplication) {
throw new Error('getAccessToken attempted before authentication initialized');
}
try {
return await userAgentApplication.acquireTokenSilent(['openid']);
} catch (error) {
console.log(error);
return '';
}
};
let userAgentApplication:Msal.userAgentApplication;
const createAuthorityUrl=(tenantId:string,policy:string)=>{
返回`https://${tenantId}.b2clogin.com/tfp/${tenantId}.onmicrosoft.com/${policy}`;
};
导出常量b2cLogin=(配置:B2CConfig)=>{
常量msalAppConfig={
cacheLocation:'localStorage',
重定向URI:`${location.protocol}/${location.host}`,
navigateToLoginRequestUrl:错误,
是的,
验证权限:false,
};
const{clientId,tenantId,myb2csignipolicy,myb2cPasswordResetPolicy}=config;
返回新承诺(解决=>{
让handlingPasswordReset=false;
const app=新的Msal.UserAgentApplication(
clientId,
createAuthorityUrl(租户、myb2cSigninPolicy),
(errorDesc:string,token:string)=>{
if(errorDesc&&errorDesc.indexOf('AADB2C90118')>-1){
//用户忘记密码
// https://github.com/Azure-Samples/active-directory-b2c-javascript-msal-singlepageapp/issues/9#issuecomment-347556074
handlingPasswordReset=true;
新Msal.UserAgentApplication(
clientId,
createAuthorityUrl(租户、myb2cPasswordResetPolicy),
()=>空,
msalAppConfig,
).loginDirect();
}
返回解析(令牌);
},
msalAppConfig,
);
如果(!handlingPasswordReset){
userAgentApplication=app;
}
//如果在iframe中运行,MSAL的acquireTokenSilent()似乎无法解析
如果(window.parent!==window){
返回解析(“”);
}
if(!userAgentApplication.isCallback(location.hash))解析(getAccessToken());
});
};
export const getAccessToken=async():Promise=>{
如果(!userAgentApplication){
抛出新错误('getAccessToken在初始化身份验证之前尝试过');
}
试一试{
return wait userAgentApplication.acquireTokenSilent(['openid']);
}捕获(错误){
console.log(错误);
返回“”;
}
};
错误HTTP 400:头请求的大小太长通常是因为有太多cookie或cookie太大
参考:
请求头太长,当您在已加载portal.azure.com的同一浏览器会话中加载应用程序时,可能会出现此问题。您是否在private window/其他浏览器中尝试过并看到相同的问题?当它是private window时,即使在已开发的环境中,我也不会收到错误的请求消息。是的,只有在您并排运行应用程序和portal.azure.com时才会出现此问题,并且这是一个已知问题。这不会影响客户。当您验证时,请尝试在私人窗口中进行验证。您能为我提供有关此已知问题的参考资料吗。。