从外部登录回调后的服务器端处理

问题描述 投票:0回答:1

我在使用ASP.Net Identity的项目中启用了第三方登录。在最初的发帖请求之后,我通过第三方登录进行重定向,并返回到OnGetCallbackAsync。但是,我想使用usermanager创建一个帐户,然后重定向到其他页面。

public IActionResult OnPost ( string provider, string returnUrl = null )
{
    // Request a redirect to the external login provider.
    var redirectUrl = Url.Page( "./ExternalLogin", pageHandler: "Callback", values: new { returnUrl } );
    var properties = _signInManager.ConfigureExternalAuthenticationProperties( provider, redirectUrl );
    return new ChallengeResult( provider, properties );
}

public IActionResult OnGetAsync ()
{
    return RedirectToPage( "./Login" );
}

public async Task<IActionResult> OnGetCallbackAsync ( string returnUrl = null, string remoteError = null )
{
    ...
   return Page()
}

public async Task<IActionResult> OnPostConfirmationAsync ( string returnUrl = null )
{
   ... //create accounts etc.
   return LocalRedirect( returnUrl );
}

当它从第三方提供者返回时,它命中了我的OnGetCallbackAsync方法。然后执行一些逻辑操作,显示用户输入电子邮件和提交按钮的页面。当他们提交时,它将按帖子确认方法,并根据输入的电子邮件和第三者信息创建用户。

我的问题是我想跳过用户输入任何信息或必须单击另一个提交按钮的步骤。

我应该担心让请求保持等幂吗?如果是,我该如何处理该发布请求或进行我需要做的服务器端处理?

c# asp.net-core razor asp.net-core-identity
1个回答
0
投票

如果您需要自动重定向,您可以只从OnGetCallbackAsync调用OnPostConfirmationAsync。像这样的东西

public IActionResult OnPost ( string provider, string returnUrl = null )
{
    // Request a redirect to the external login provider.
    var redirectUrl = Url.Page( "./ExternalLogin", pageHandler: "Callback", values: new { returnUrl } );
    var properties = _signInManager.ConfigureExternalAuthenticationProperties( provider, redirectUrl );
    return new ChallengeResult( provider, properties );
}

public IActionResult OnGetAsync ()
{
    return RedirectToPage( "./Login" );
}

public async Task<IActionResult> OnGetCallbackAsync ( string returnUrl = null, string remoteError = null )
{
    ...
   return await OnPostConfirmationAsync(returnUrl);
}

public async Task<IActionResult> OnPostConfirmationAsync ( string returnUrl = null )
{
   ... //create accounts etc.
   return LocalRedirect( returnUrl );
}
© www.soinside.com 2019 - 2024. All rights reserved.