VB版ASP.NET Web应用集成Azure AD Auth库遇CORS问题求助
Azure AD身份验证集成到VB ASP.NET Web应用(.NET Framework)时的CORS问题
我正尝试将Microsoft Azure AD Authentication库集成到已有的VB ASP.NET Web Application(.NET Framework)项目中,但在向微软登录服务器发起身份验证挑战时遇到了CORS问题。浏览器控制台报错,代码基于某教程视频转译为VB,在新建测试项目中可正常运行,但现有项目中出现问题。
问题出在AdLogin()子过程中的Page.Request.GetOwinContext.Authentication.Challenge()方法——该方法本该重定向到微软登录验证页面,却触发了CORS错误。我已经确认租户ID、应用ID和授权字符串均正确,尝试过配置多个重定向URI和CORS设置,但都没解决问题,希望得到技术建议。
身份验证启动代码
Public Sub ConfigureAuth(ByVal app As IAppBuilder) IdentityModelEventSource.ShowPII = True ServicePointManager.Expect100Continue = True ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12 Or SecurityProtocolType.Ssl3 app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType) app.UseCookieAuthentication(New CookieAuthenticationOptions()) app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll) app.UseOpenIdConnectAuthentication(New OpenIdConnectAuthenticationOptions With { .ClientId = appID, .Authority = authority, .RedirectUri = redirectUri, .PostLogoutRedirectUri = redirectUri, .TokenValidationParameters = New TokenValidationParameters() With { .ValidateIssuer = False }, .Notifications = New OpenIdConnectAuthenticationNotifications() With { .AuthenticationFailed = AddressOf OnAuthenticationFailedAsync, .AuthorizationCodeReceived = AddressOf OnAuthorizationCodeReceivedAsync } }) app.UseStageMarker(PipelineStage.Authenticate) End Sub
登录代码
Private Sub AdLogin() Dim authProperties As AuthenticationProperties = New AuthenticationProperties() authProperties.RedirectUri = "https://localhost:14699/" authProperties.AllowRefresh = False authProperties.ExpiresUtc = DateTime.UtcNow.AddMinutes(20) Page.Request.GetOwinContext.Authentication.Challenge( authProperties, OpenIdConnectAuthenticationDefaults.AuthenticationType) End Sub
内容的提问来源于stack exchange,提问作者activeinfor
相关产品推荐
相关产品推荐

