.net core Microsoft登录无需重定向url即可工作

.net core Microsoft登录无需重定向url即可工作,.net-core,oauth-2.0,blazor-server-side,microsoft-account,.net Core,Oauth 2.0,Blazor Server Side,Microsoft Account,当我在Blazor应用程序中使用Microsoft OAuth登录时,authenticateResult.successed为true,即使我没有指定重定向URI。如果我不将我的URI添加到OAuth客户机中,它就会像谷歌预期的那样失败 根据OAuth2.0规范,在没有重定向URI的情况下,它不应该工作: 授权服务器必须需要公共客户端,并且应该 要求机密客户端注册其重定向URI 我正在将Microsoft.AspNetCore.Authentication.MicrosoftAccount 3

当我在Blazor应用程序中使用Microsoft OAuth登录时,authenticateResult.successed为true,即使我没有指定重定向URI。如果我不将我的URI添加到OAuth客户机中,它就会像谷歌预期的那样失败

根据OAuth2.0规范,在没有重定向URI的情况下,它不应该工作:

授权服务器必须需要公共客户端,并且应该 要求机密客户端注册其重定向URI

我正在将Microsoft.AspNetCore.Authentication.MicrosoftAccount 3.0.3与.NET Core 3.0一起使用

我的应用程序的身份验证设置如下所示(我实际上在设置中使用的是localhost:12345,但我的应用程序运行的不是此设置..):


讽刺的是,最后一句可能解释了这一点,但我甚至不知道MicrosoftAccount库使用的是哪一个流,我只在谷歌搜索时获得一般文档。

当使用完全不同的域,而不是具有不同端口的本地主机时,它会按预期失败。我想这已经足够好了


此外,我未选中“ID令牌”和“将应用程序视为公共客户端”,因此,据我所知,应该使用授权代码流。

当使用完全不同的域而不是具有不同端口的本地主机时,它会按预期失败。我想这已经足够好了

此外,我未选中“ID令牌”和“将应用程序视为公共客户端”,因此,据我所知,应该使用授权代码流

public class ExternalLoginModel : PageModel
{
    public IActionResult OnGetAsync(string externalAuthType, string returnUrl)
    {
        var authenticationProperties = new AuthenticationProperties
        {
            RedirectUri = Url.Page("./externallogin",
            pageHandler: "Callback",
            values: new { returnUrl }),
        };

        return new ChallengeResult(externalAuthType, authenticationProperties);
    }

    public async Task<IActionResult> OnGetCallbackAsync(
        string returnUrl = null, string remoteError = null)
    {
        var authenticateResult = await HttpContext.AuthenticateAsync("External");

        if (!authenticateResult.Succeeded) // Should be false for Microsoft sign in
            return BadRequest();

        ...

        return LocalRedirect(returnUrl);
    }
}
        services.AddAuthentication(o =>
        {
            o.DefaultSignInScheme = "External";
        }).AddCookie("External");
        services.AddAuthentication().AddGoogle(google =>
        {
            google.ClientId = Configuration["Authentication:Google:ClientId"];
            google.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
        });
        services.AddAuthentication().AddMicrosoftAccount(microsoftOptions =>
        {
            microsoftOptions.ClientId = Configuration["Authentication:Microsoft:ClientId"];
            microsoftOptions.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
        });