当前位置: 首页 > 知识库问答 >
问题:

Azure AD Easy身份验证过期,出现CORS错误

姜聪
2023-03-14

问题与Azure相关,即使用户正在积极使用应用程序,也会出现Easy Auth过期的情况。根据分享的解释,简单的身份验证机制似乎并不适合Azure Web应用上托管的SPA?MS是否可以在官方文档下添加提到的选项-“https://docs.microsoft.com/en-in/Azure/app-service/app-service-authentication-overview?toc=%2fazure%2fapp-service-web%2ftoc.json”

我面临以下问题:当AppServiceAuthSession cookie过期时,对基础安全API调用的任何SPA AJAX请求都失败,并出现CORS问题:无法加载https://login.windows.net//oauth2/authorize?response_type=code+id_token&redirect_uri=https%3a%2f%2fapp.contoso.com%2f.auth%2flogin%2faad%2fcallback&client_id=xxxxx&scope=openid+profile+email&response_mode=form_post&nonce=xxxxx&state=redir%3d%252fget-dataapi:从'https:'重定向//login.windows.net/xxxxxxxxx/oauth2/authorize?response_type=code+id_token&redirect_uri=https%3a%2f%app.contoso.com%2f.auth%2flogin%2faad%2fcallback&client_id=xxxxx&scope=openid+profile+email&response_mode=form_post&nonce=xxxxx&state=Redirect%3d%252fapi%252fv2%252fget-dataapi“to”https://login.microsoftonline.com/xxxxxxxxx/oauth2/authorize?t_uri=https%3a%2f%app.contoso.com%2f.auth%2flogin%2faad%2fcallback&client_id=xxxxxxxx&scope=openid+profile+email&response_mode=form_post&nonce=xxxxxxxxxx&staTE=Redir%3d%252FAPI%252Fv2%252FGet-DataAPI“已被CORS策略阻止:请求得资源上没有”Access-Control-Allow-Origin“标头.因此,不允许访问来源“https://app.contoso.com”。如果一个不透明的响应满足您的需要,请将请求的模式设置为“no-cors”以获取禁用CORS的资源。

共有1个答案

楮景明
2023-03-14

我面临以下问题:当AppServiceAuthSession cookie过期时,对底层安全API调用的任何SPA AJAX请求都将失败,并出现CORS问题

根据我的理解,您在SPA中使用了内置的App Service身份验证/授权(EasyAuth)功能,而没有编写任何代码或使用客户端库在SPA中进行身份验证。

对于带有无效cookie或令牌的Ajax请求,我可能会遇到类似的问题,如下所示:

client.login("aad").done(function (results) {
     alert("You are now logged in as: " + results.userId);
     console.log("x-zumo-auth token is: "+ results.mobileServiceAuthenticationToken);
}, function (err) {
     alert("Error: " + err);
});

此外,您还可以通过使用juunas评论的Active Directory Authentication Library(ADAL)for JavaScript直接检索AAD id_token或access_token,然后在授权头中包含令牌(id_token,access_token)作为承载令牌来请求WebAPI。

此外,您可以使用客户端流身份验证服务,并通过adal.js检索id_token或access_token,然后使用前一个令牌使用EasyAuth登录以检索authenticationtoken作为x-zumo-token,然后使用x-zumo-token请求您的WebAPI。

 类似资料:
  • 尝试将Azure AD身份验证添加到具有. net核心2.1后端的Angular 7 webapp。 然而,我在请求过程中收到了CORS错误。 “访问位于的XMLHttpRequest”https://login.microsoftonline.com/.......“(重定向自”https://localhost:5001/api/auth/login“)起源”https://localhost

  • 以下是我的java mail API代码: 我尝试了2-3个不同的电子邮件id作为发件人id。。但仍然会发生错误。 下面是代码的输出: 发生了一些错误,错误为javax。邮政AuthenticationFailedException:535-5.7.8不接受用户名和密码。在535 5.7.8了解更多信息https://support.google.com/mail/?p=BadCredential

  • 问题内容: 因为在AngularJS中使用CORS和http身份验证可能会比较棘手,所以我编辑了问题以分享一个经验教训。首先,我要感谢igorzg。他的回答对我很有帮助。场景如下:您想使用AngularJS $ http服务将POST请求发送到另一个域。获取AngularJS和服务器设置时,需要注意一些棘手的事情。 第一:在您的应用程序配置中,您必须允许跨域调用 第二:您必须指定withCrede

  • 我正在Angular中实现Azure Active Directory B2C身份验证。我正在使用msal拦截器连接Azure广告B2C。身份验证请求失败并出现错误 访问“https://login.microsoftonline.com/...”的XMLHttpRequest从来源“http://localhost/..."已被CORS策略阻止:请求的资源上没有“访问-控制-允许-来源”标头。

  • cluster=hfactory.getOrCreateCluster(“test cluster”,“localhost:9160”,凭据); 但不幸的是,它给了我一个错误: HFactory类型中的方法getOrCreateCluster(String,CassandraHostConfigurator,Map)不适用于参数(String,String,Map)

  • 我有一个问题,通过mongo shell连接到MongoDB地图集,即使我已经做了一切正确的和三重检查数据用户名和密码,包括我的IP在白名单中,更改库名测试,并尝试在同一行中添加-密码 `$mongo“mongodbsrv://cluster******.mongodb。net/test”--用户名admin--密码admin MongoDB shell v4.4.6版连接到:mongodb://