AuthenticationManager.GetExternalLoginInfoAsync always null
After have all Microsoft.Owin.Security.*
updated I found that login failed (GetExternalLoginInfoAsync
returns null) in case ASP.Net_SessionId cookie haven't created yet, but can login if it exists. So putting code Session["logging"]=true
on Login page loading solves the problem.
It's also mentioned here
GetExternalLoginInfoAsync always return null when i trying login using Facebook or Google
I have solved my problem by adding this code
context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
in the class:
private class ChallengeResult : HttpUnauthorizedResult
{
public ChallengeResult(string provider, string redirectUri)
: this(provider, redirectUri, null)
{
}
public ChallengeResult(string provider, string redirectUri, string userId)
{
LoginProvider = provider;
RedirectUri = redirectUri;
UserId = userId;
}
public string LoginProvider { get; set; }
public string RedirectUri { get; set; }
public string UserId { get; set; }
public override void ExecuteResult(ControllerContext context)
{
// this line fixed the problem with returing null
context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
if (UserId != null)
{
properties.Dictionary[XsrfKey] = UserId;
}
context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
}
}
It fixed my problem with returning NULL
.
Notice: don't use fiddler when logging with twitter authorization. You will receive error.
ASP Identity GetExternalLoginInfoAsync always return null
So the reason I'm getting null is because I put app.UseSteamAuthentication("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
before app.CreatePerOwinContext
in Startup.Auth.cs
public void ConfigureAuth(IAppBuilder app)
{
app.UseSteamAuthentication("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //if you put it here, it won't work
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
//rest of the code here
}
so I change it to :
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
//rest of the code here
app.UseSteamAuthentication("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //works!
}
GetExternalLoginInfoAsync() loginInfo return null - but only after a few hours
I had the same problem. After googling a little, I've discovered this is a known bug in Owin, because of the way they handle cookies.
This issue was submitted to Katana Team, but it looks they won't fix it at all. There are many workarounds for this, but this was the simplest I could find:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
ControllerContext.HttpContext.Session.RemoveAll();
// Request a redirect to the external login provider
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
See this question for more details about this bug, and let me know if this works well for you.
Related Topics
How to Convert a Class into Dictionary<String,String>
System.Badimageformatexception: Could Not Load File or Assembly
How to Create a New Language for Use in Visual Studio
Datetime.Parse("2012-09-30T23:00:00.0000000Z") Always Converts to Datetimekind.Local
What Is Meant by "Managed" VS "Unmanaged" Resources in .Net
Calculate a Md5 Hash from a String
Step by Step Tutorial to Use Sap. Net Connector with VS 2008
Convert an Object to an Xml String
How to Do Logging in C# Without Using 3Rd Party Libraries
Spinwait VS Sleep Waiting. Which One to Use
Return Content with Ihttpactionresult for Non-Ok Response
System.Drawing Out of Memory Exception