This project has moved and is read-only. For the latest updates, please go here.

How to get claims out of OWIN middleware. I only see claims of LOCAL AUTHORITY

Oct 27, 2014 at 7:57 PM
Hi,
I have setup Facebook like next:
           FacebookAuthenticationOptions faceBookAccountOptions = new FacebookAuthenticationOptions();
            faceBookAccountOptions.AppId = "*";
            faceBookAccountOptions.AppSecret = "*";
            faceBookAccountOptions.Provider = new FacebookAuthenticationProvider()
            {
                OnAuthenticated = (context) =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken));
                        return Task.FromResult(0);
                    }
            };
            //faceBookAccountOptions.Scope.Add("urn:facebook:access_token");
            //faceBookAccountOptions.Scope.Add("access_token");
            app.UseFacebookAuthentication(faceBookAccountOptions);
For some reason I cannot add any claim next to the 4 of the ASP.NET identity (LOCAL AUTHORITY). I see various posts on how to fix this. One of them is in the code snippet above.

Can anybody guide me how to add additional claims?

J.
Oct 27, 2014 at 9:33 PM
Edited Oct 27, 2014 at 9:34 PM
Hi,
Can it be that there is a bug in the sample code of MVC?

I have next code. In A there are claims, but in B they are not passed/ used. And what about C. on next authentications?

J.
//
        // POST: /Account/ExternalLoginConfirmation
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
[*** A ***]                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                // Sign in this external identity if its already linked        
                var externUser = await UserManager.FindAsync(info.Login);
                if (externUser != null)
                {
[*** C ***] await SignInManager.SignInAsync(externUser, isPersistent: false, rememberBrowser: false);
                    return RedirectToLocal(returnUrl);
                }

                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
[*** B ***]                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Oct 27, 2014 at 11:56 PM