Search code examples
c#asp.net-core-2.0instagram-api

Instagram OAuth Provider - Authentication issue


I'm trying to authenticate with Instagram as an external login provider in a .Net Core 2.0 application. My middleware configuration looks like this: Startup.cs

services.AddAuthentication().AddInstagram(options =>
{
   options.ClientId = ApplicationSettings.InstagramSettings.ApplicationId;
   options.ClientSecret =ApplicationSettings.InstagramSettings.ApplicationSecret;
   options.Scope.Add(ApplicationSettings.InstagramSettings.Permissions);
   options.SaveTokens = true; 
});

ExternalLogin method in AccountController is unchanged:

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public IActionResult ExternalLogin(string provider, string returnUrl = null)
    {
        // Request a redirect to the external login provider.
        var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl });
        var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

        return Challenge(properties, provider);
    }

Yet, when

var info = await _signInManager.GetExternalLoginInfoAsync();

is called in the ExternalLoginCallback(), I get null as result.

NOTE:

  • This works perfectly fine for Facebook provider, with no other settings in the middleware configuration.
  • If I inspect the network activity in Fiddler, I can see that the Instagram successfully sends the access_token back to my application, only that GetExternalLoginInfoAsync() can't read it.

Any ideas?


Solution

  • There was a bug in the version of Instagram OAuth provider that I used (2.0.0-rc2-final) that prevents the user info response from being correctly processed. I switched to the latest RTM nightly build of the package where the bug was fixed.