我使用 azure 函数来托管 React 应用程序的 API,但我也使用相同的 azure 函数来托管应用程序的 html/js/css(通过 Blob 存储上的静态文件的代理函数)。
我一直在使用 EasyAuth 为其提供身份验证,效果非常好,但是我需要支持未内置于 EasyAuth 中的身份提供程序(并且它根本不支持自定义身份提供程序)。这意味着我将重新使用 Microsoft.AspNetCore.Authentication.OpenIdConnect 包。
我已在启动文件中注册了身份验证
builder.Services
.AddAuthentication()
.AddCookie("WebJobsAuthLevel") //errors without this, although I suspect it's wrong
.AddCookie("Bearer") //errors without this, although I suspect it's wrong
.AddOpenIdConnect("custom", o =>
{
o.MetadataAddress = "https://localhost:44320/.well-known/openid-configuration";
o.ClientId = "clientid";
o.ClientSecret = "secret";
o.ResponseMode = OpenIdConnectResponseType.Code;
o.SignInScheme = "Cookies";
o.GetClaimsFromUserInfoEndpoint = true;
});
以及一个可以让我触发挑战的功能
[FunctionName("CustomAuth")]
public async Task<IActionResult?> Challenge([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = ".auth/login/custom")]HttpRequest req, ILogger log)
{
return new ChallengeResult("custom");
}
如果我点击此功能,它会很好地工作,重定向到身份验证提供程序进行登录。
但是,一旦我登录,它就会重定向回我的功能应用程序,其中 404
http://localhost:7071/signin-oidc?querystringhere http://localhost:7071/signin-oidc?querystringhere
在这个阶段,我猜测 AddAuthentication 无法像在 ASP.NET MVC 核心中使用它时那样挂钩传入的 Web 请求。想知道是否有一种已知的方法可以将其连接起来,无论是在较低级别还是通过自定义天蓝色函数