【发布时间】:2022-06-10 21:25:45
【问题描述】:
我们正在我们的网络服务器上托管一个网站。该网站需要连接到 Azure/Adfs。用户需要通过 Azure/Adfs 登录才能访问网站的某些部分。
但它只工作了一半。我可以在“customer.nl”上连接,但在“subdomain.customer.nl”上我收到“NONCE 错误”。
有一个“Startup”类,它继承自“UmbracoDefaultOwinStartup”(常规 OwinStartup 的 Umbraco 覆盖)。该类有一个“ConfigureAuth”方法,用于设置配置参数。其中之一是 RedirectUri,它(通过 web.config)设置为“customer.nl”。
“启动”代码:
[assembly: OwinStartup(typeof(Ip.Startup))]
namespace Customername {
public class Startup : UmbracoDefaultOwinStartup {
string redirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];
public new void Configuration(IAppBuilder app) {
ConfigureAuth(app);
app.MapSignalR();
base.Configuration(app);
}
public void ConfigureAuth(IAppBuilder app) {
app.SetDefaultSignInAsAuthenticationType(
CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions(){
CookieManager = new SystemWebCookieManager()
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions {
ClientId = clientId,
Authority = authority,
RedirectUri = redirectUri,
PostLogoutRedirectUri = redirectUri,
Scope = OpenIdConnectScope.OpenIdProfile,
ResponseType = OpenIdConnectResponseType.IdToken,
TokenValidationParameters = new TokenValidationParameters() {
ValidateIssuer = false
},
Notifications = new OpenIdConnectAuthenticationNotifications {
AuthenticationFailed = OnAuthenticationFailed
}
});
}
}
}
如果我尝试登录“subdomain.customer.nl”,我会重定向到 login.microsoftonline.com,但我在 URL 中看到“redirect_url=customer.nl”。
重定向未认证用户的函数是:
public void SignIn(string ReturnUrl = "/") {
if (!Request.IsAuthenticated) {
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = ReturnUrl },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
}
但更改此函数中的 RedirectUri 不会更改 login.microsoftonline.com 网址中的“Redirect_Uri”。
如果我登录 subdomain.customer.nl,我会返回到 customer.nl,并带有以下查询字符串(我已经解码了 URL):
https://www.customer.nl/?errormessage=IDX21323:
RequireNonce is '[PII is hidden]'.
OpenIdConnectProtocolValidationContext.Nonce was null,
OpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce was not null.
The nonce cannot be validated.
If you don't need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to 'false'. Note if a 'nonce' is found it will be evaluated.
我的猜测是,当 redirect_uri 与 origin-url (subdomain.customer.nl != customer.nl) 不匹配时会弹出 NONCE 错误。
这是正确的吗?如果是这样,我如何将 Redirect_Uri 更改为用户正在访问的子域?在启动时设置它似乎不是要走的路。
【问题讨论】:
标签: c# azure azure-active-directory nonce