当我在Blazor应用中使用Microsoft OAuth登录时,即使我未指定重定向URI ,authenticateResult.Succeeded也为true。它的失败是用于谷歌,如果我没有我的URI添加到OAuth用户端。
Imo,根据OAuth2.0规范,如果没有重定向URI,它将不起作用:
授权服务器必须要求公共客户端,应该要求机密客户端注册其重定向URI。
我正在将Microsoft.AspNetCore.Authentication.MicrosoftAccount 3.0.3与.NET Core 3.0一起使用
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"];
});
我的应用程序的身份验证设置如下所示(我实际上在设置中使用localhost:12345,但这不是我的应用程序正在运行的..):
具有讽刺意味的是,最后一句话可能解释了这一点,但是我什至不知道MicrosoftAccount库正在使用哪个流,并且在谷歌搜索时我只会得到通用文档。
当使用完全不同的域而不是具有不同端口的localhost时,它会按预期失败。我想那已经足够了。
另外,我未选中“ ID令牌”和“作为公共客户端处理应用程序”,因此,据我所知,应使用授权代码流。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句