skip to Main Content

I have ASP.NET 5 project and I am using Web API to establish the external login (for Facebook and Google). In my case, I have Web API controller (Not MVC controller) which contains the following code :

[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();

when the mobile application calling this method, I am getting the request authenticated correctly and the property User.Identity.IsAuthenticated is true, and I can see in the debugger, that the user is correct, but the problem is the exlog variable is always coming null.

here is the Authentication property

private IAuthenticationManager Authentication => this.Request.GetOwinContext().Authentication;

I read every question on the stack about this bug, but nothing helped me, most of the questions are for the MVC controller, so that did not help.

for example, this question did not help me because it is for MVC.

Update
I am using Owin 4.0

3

Answers


  1. Chosen as BEST ANSWER

    For all the people who asked me in the comments to put my answer.
    Actually, the problem has not been solved and I did not find a solution for this,
    I am sorry to say that.

    What I discovered is that I do not need to call this method from the beginning.
    and I went completely another way (I do not remember how and why)

    Just small advice: consider the situation again and reconsider if you really need to call this method.

    I wish I had been more helpful, I am sorry.


  2. You are getting “NULL” because you didn’t write the code if the IsAuthenticated = true then what should it do? (means redirection to any page or else).

    see carefully your if condition for IsAuthenticated:
    if (!User.Identity.IsAuthenticated)

    May be this can help you.

    Login or Signup to reply.
  3. Try to enable Google + API in the Google console. Also make sure the secret key is not concatenated with a space at the end after you paste it to your code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search