Exemplo n.º 1
0
        public async Task CreateLogin(
            IUserLogin userLogin,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (userLogin == null)
            {
                throw new ArgumentException("userLogin can't be null");
            }
            if (userLogin.LoginProvider.Length == -1)
            {
                throw new ArgumentException("userLogin must have a loginprovider");
            }
            if (userLogin.ProviderKey.Length == -1)
            {
                throw new ArgumentException("userLogin must have a providerkey");
            }
            if (userLogin.UserId == Guid.Empty)
            {
                throw new ArgumentException("userLogin must have a user id");
            }

            var login = UserLogin.FromIUserLogin(userLogin);

            dbContext.UserLogins.Add(login);

            int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken)
                               .ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task CreateLogin(
            IUserLogin userLogin,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (userLogin == null)
            {
                throw new ArgumentException("userLogin can't be null");
            }
            if (userLogin.LoginProvider.Length == -1)
            {
                throw new ArgumentException("LoginProvider must be provided");
            }
            if (userLogin.ProviderKey.Length == -1)
            {
                throw new ArgumentException("ProviderKey must be provided");
            }
            if (userLogin.UserId == Guid.Empty)
            {
                throw new ArgumentException("UserId must be provided");
            }
            if (userLogin.SiteId == Guid.Empty)
            {
                throw new ArgumentException("SiteId must be provided");
            }

            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            //await EnsureProjectId().ConfigureAwait(false);
            var projectId = userLogin.SiteId.ToString();

            var login = UserLogin.FromIUserLogin(userLogin);

            // this will be a tricky one for queries because the key consists of 4 columns
            // TODO: review this and whether we really need all the  parts of the key in EF
            // http://www.jerriepelser.com/blog/using-aspnet-oauth-providers-without-identity
            // ProviderKey is the unique key associated with the login on that service
            var key = login.UserId.ToString()
                      + "~" + login.SiteId.ToString()
                      + "~" + login.LoginProvider
                      + "~" + login.ProviderKey;

            await loginCommands.CreateAsync(
                projectId,
                key,
                login,
                cancellationToken).ConfigureAwait(false);
        }