I am using OWIN Oauth Instagram to sign in on my MVC 5 application with the following code:
Startup.Auth.cs
app.UseInstagramAuthentication(new InstagramAuthenticationOptions()
{
ClientId = "myCID",
ClientSecret = "mySecret",
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
Provider = new InstagramAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
context.Identity.AddClaim(new Claim("igAccessToken", context.AccessToken));
context.Identity.AddClaim(new Claim("igFullName", context.FullName));
context.Identity.AddClaim(new Claim("igProfilePic", context.ProfilePicture));
context.Identity.AddClaim(new Claim("igUsername", context.UserName));
foreach (var claim in context.User)
{
var claimType = string.Format("{0}", claim.Key);
string claimValue = claim.Value.ToString();
if (!context.Identity.HasClaim(claimType, claimValue))
context.Identity.AddClaim(new Claim(claimType, claimValue, "XmlSchemaString", "Instagram"));
}
return Task.FromResult(0);
}
}
});
Login works and I am able to store this information in AspNetUserRoles table by adding new columns to hold the data respectively but I don't think is the best method nor do I know how to access the info. How do I access this data with something like:
SomeController.cs
var info = await AuthenticationManager.GetExternalLoginInfoAsync();
var pic = info.ExternalIdentity.Claims.First(c => c.Type == "igProfilePic").Value;
var fullName = info.ExternalIdentity.Claims.First(c => c.Type == "igFullName").Value;
var accessToken = info.ExternalIdentity.Claims.First(c => c.Type == "igAccessToken").Value;
The code above throws a Object reference not set to an instance of an object.
and after debugging it, there is nothing in the info context leading me to believe the claim is never stored in the ExternalIdentity context?
Note: There are quite a few similar questions but they seem outdated and don't work for me since a lot of my code is borrowed from these questions.