我在我的ASP.NET核心应用中使用社交媒体登录。除了几个页面之外,整个应用程序都需要对用户进行身份验证。
我有一个允许匿名用户的登录页面,并重定向到登录页面,它添加了一个URL参数,例如myapp.com/ login ?id=omeid12345
我的控制器中有三个允许用户使用其社交媒体帐户登录的操作。第一个页面只是呈现登录按钮的基本页面。在第一步中,我可以很容易地捕获Id。
[AllowAnonymous]
public IActionResult Login([FromQuery] string id)
{
// So I can capture the Id here
}一旦用户点击了他选择的社交媒体登录,我们就会执行以下操作:
[AllowAnonymous]
public async Task ExternalLogin(string provider, string returnUrl, string myId)
{
var properties = new AuthenticationProperties
{
RedirectUri = "Login/Callback"
};
// Add returnUrl to properties -- if applicable
if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
properties.Items.Add("returnUrl", returnUrl);
// Add url param Id to properties -- if applicable
if (!string.IsNullOrEmpty(myId))
properties.Items.Add("myId", myId);
await HttpContext.Authentication.ChallengeAsync(provider, properties);
return;
}我的问题是,我如何在回调操作中获取我的Id?
[AllowAnonymous]
public async Task<IActionResult> Callback()
{
// I can get user info here once authenticated by social media provider
var user = HttpContext.User;
// How do I get myId?
}https://stackoverflow.com/questions/41540041
复制相似问题