Are there some hidden guard conditions for IUserLoginStore::AddLoginAsync?

Aug 5, 2014 at 10:21 PM
I am splitting up the calls to the User and Login stores for the identity framework to match a clients layered architecture. Basically a webapi fronts the Microsoft.AspNet.Identity.EntityFramework.UserStore. I have this working correctly for aspnetUsers table. I am also seeing queries executed against the AspNetUserLogins table so I believe I have setup the store correctly. However when i call AddLoginAsync, nothing happens. I have confirmed I have values for the user.Id, login.ProviderKey and login.LoginProvider. The user.Id matches an existing user in AspNetUsers table.

Is there some other data that is required for an add to work?

Thanks!
Aug 6, 2014 at 6:05 PM
Since nobody is biting, here is some more detail. The web application has a UserStore<ApplicationUser> setup but instead of using the default entityframework UserStore, it makes httpclient calls to a webapi 2 project. This in turn calls my custom store, currently wrapping the EntityFramework default store as shown below. All of this works correctly except for adding a login: i.e I can add users this way, query users and logins. I have verified that when AddLoginAsync is called, no sql sent to the databse via sql profiler. I stuck in some error handling just in case the UserStore was trying to tell me something, but it silently fails.

Here is the repository implementation, stripped a bit to shorten it up for posting here.
using System;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using SHP.CommonTypes.WebFramework;

namespace SHP.DAL.WebFramework
{
    public class UserRepository 
    {
        private UserStore<ApplicationUser> _backend = new UserStore<ApplicationUser>(new ApplicationDbContext());

        // IUserStore methods 
        public async Task CreateAsync(ApplicationUser user)
        {
            await _backend.CreateAsync(user);
        }

        public async Task UpdateAsync(ApplicationUser user)
        {
            await _backend.UpdateAsync(user);
        }

        public async Task<ApplicationUser> FindByIdAsync(string userId)
        {
            var user = await _backend.FindByIdAsync(userId);
            return user;
        }

        public async Task<ApplicationUser> FindByNameAsync(string userName)
        {
            var user = await _backend.FindByNameAsync(userName);
            return user;
        }

        //IUserLoginStore methods
        public async Task AddLoginAsync(ApplicationUser user, UserLoginInfo login)
        {
            ExceptionDispatchInfo capturedException = null;
            try
            {
                await _backend.AddLoginAsync(user, login);
            }
            catch (Exception ex)
            {
                capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            if (capturedException != null)
            {
                await ExceptionHandler();

                capturedException.Throw();
            }
        }

        private async static Task ExceptionHandler() { }

        public async Task<ApplicationUser> FindAsync(UserLoginInfo login)
        {
            var user = await _backend.FindAsync(login);
            return user;
        }
    }
    
}
Any ideas of things to try to make this code do an sql insert with AddLoginAsync would be appreciated!