我有 ASP.NET 5 项目,我正在使用 Web API 建立外部登录(用于 Facebook 和 Google)。就我而言,我有包含以下代码的 Web API Controller (不是 MVC Controller ):
[OverrideAuthentication]
[HostAuthentication(DefaultAuthenticationTypes.ExternalCookie)]
[AllowAnonymous]
[Route("ExternalLogin", Name = "ExternalLogin")]
public async Task<IHttpActionResult> GetExternalLogin(string provider, string error = null)
{
if (error != null)
return Redirect(Url.Content("~/") + "#error=" + Uri.EscapeDataString(error));
if (!User.Identity.IsAuthenticated)
return new ChallengeResult(provider, this);
var exLog = await Authentication.GetExternalLoginInfoAsync();
当移动应用程序调用此方法时,我正在正确验证请求并且属性 User.Identity.IsAuthenticated
为真,我可以在调试器中看到用户是正确的,但问题是 exlog
变量总是为空。
这里是Authentication
属性
private IAuthenticationManager Authentication => this.Request.GetOwinContext().Authentication;
我阅读了有关此错误的堆栈中的每个问题,但对我没有任何帮助,大多数问题都是针对 MVC Controller 的,因此没有帮助。
例如,this question对我没有帮助,因为它是针对 MVC 的。
更新 我正在使用 Owin 4.0
最佳答案
对于所有在评论中要求我回答的人。
实际上,问题并没有解决,我也没有找到解决办法,
很抱歉这么说。
我发现我不需要从一开始就调用这个方法。
我完全走了另一条路(我不记得是怎么走的,为什么走)
小建议:再考虑一下情况,再考虑是否真的需要调用这个方法。
我希望我能提供更多帮助,对不起。
关于c# - ASP.NET Web API Authentication.GetExternalLoginInfoAsync 总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50604415/