在ASP.Net Core应用程序中,要设置OAuth2回调URL,需要在Startup.cs文件中的ConfigureServices方法中添加如下代码:
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "OAuth2";
})
.AddCookie("Cookies")
.AddOAuth("OAuth2", options =>
{
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.CallbackPath = new PathString("/signin-oauth");
options.AuthorizationEndpoint = "https://example.com/oauth2/authorize";
options.TokenEndpoint = "https://example.com/oauth2/token";
});
其中,CallbackPath属性是用于指定回调URL的。在上面的示例中,它被设置为/signin-oauth。如果您想要将它设置为其他值,请确保使用的URL与在OAuth提供程序中注册的回调URL相匹配。