コード例 #1
0
        void IAuthenticationManager.UpdateUser(HttpContextBase context, IAnonymousUser user, UserType preferredUserType)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // Update the ASP.NET stuff.

            var identity = context.User.Identity as AnonymousUserIdentity;

            if (identity == null)
            {
                return;
            }

            if (identity.Id != user.Id)
            {
                throw new ArgumentException("The user is not the same as the current anonymous user.");
            }

            identity.PreferredUserType = preferredUserType;

            // Update the cookies.

            _cookieManager.UpdateAnonymousCookie(context, user, identity.PreferredUserType);
        }
コード例 #2
0
ファイル: AnonymousRepository.cs プロジェクト: formist/LinkMe
 AnonymousContact IAnonymousRepository.GetContact(IAnonymousUser user, ContactDetails contactDetails)
 {
     using (var dc = CreateContext().AsReadOnly())
     {
         return(GetContactByDetails(dc, user.Id, contactDetails));
     }
 }
コード例 #3
0
        /// <summary>
        /// Deletes the specified anonymous <paramref name="user"/>.
        /// </summary>
        /// <param name="user">The anonymous user.</param>
        /// <returns></returns>
        public virtual Task DeleteAsync(IAnonymousUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            return(DeleteByIdAsync(user.Id));
        }
コード例 #4
0
        /// <summary>
        /// Generate the claims for a anonymous user.
        /// </summary>
        /// <param name="user">The anonymous user to create a <see cref="ClaimsIdentity"/> from.</param>
        /// <returns>The <see cref="Task"/> that represents the asynchronous creation operation, containing the created <see cref="ClaimsIdentity"/>.</returns>
        protected virtual async Task <ClaimsIdentity> GenerateClaimsAsync(IAnonymousUser user)
        {
            var scheme = await GetCookieSchemeAsync();

            var id = new ClaimsIdentity(scheme);

            id.AddClaim(new Claim(IdentityModel.JwtClaimTypes.Subject, user.Id));

            return(id);
        }
コード例 #5
0
        public static Mock <IAnonymousUserFactory> CreateMockAnonymousUserFactory(IAnonymousUser user = null)
        {
            var mock = new Mock <IAnonymousUserFactory>();

            mock.Setup(m => m.CreateAsync(It.IsAny <string>())).ReturnsAsync(() =>
            {
                return(user);
            });

            return(mock);
        }
コード例 #6
0
        /// <summary>
        /// Creates a System.Security.Claims.ClaimsPrincipal from an anonymous user asynchronously.
        /// </summary>
        /// <param name="user">The user to create a System.Security.Claims.ClaimsPrincipal from.</param>
        /// <returns>The anonymous System.Security.Claims.ClaimsPrincipal.</returns>
        public async Task <ClaimsPrincipal> CreateAsync(IAnonymousUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var id = await GenerateClaimsAsync(user);

            return(new ClaimsPrincipal(id));
        }
コード例 #7
0
        /// <summary>
        /// Creates a anonymous user.
        /// </summary>
        /// <param name="user">The anonymous user.</param>
        /// <returns></returns>
        public async virtual Task CreateAsync(IAnonymousUser user = null)
        {
            user = user ?? await _anonUserFactory.CreateAsync();

            if (user == null)
            {
                throw new InvalidOperationException(nameof(user));
            }

            DeleteAnonymousIdCookie();
            AppendAnonymousIdCookie(user.Id);
        }
コード例 #8
0
ファイル: AnonymousRepository.cs プロジェクト: formist/LinkMe
        void IAnonymousRepository.CreateContact(IAnonymousUser user, AnonymousContact contact)
        {
            using (var dc = CreateContext())
            {
                // Ensure there is a user.

                var userEntity = GetAnonymousUserEntity(dc, user.Id);
                if (userEntity == null)
                {
                    dc.AnonymousUserEntities.InsertOnSubmit(user.Map());
                }

                dc.AnonymousContactEntities.InsertOnSubmit(contact.Map(user.Id));
                dc.SubmitChanges();
            }
        }
コード例 #9
0
        /// <summary>
        /// Signs in the specified anonymous user.
        /// </summary>
        /// <param name="user">The anonymous user.</param>
        /// <returns></returns>
        public virtual async Task SignInAsync(IAnonymousUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var principal = await _anonPrincipalFactory.CreateAsync(user);

            // add anon authentication method
            principal.Identities.First()
            .AddClaim(new Claim(IdentityModel.JwtClaimTypes.AuthenticationMethod, OidcConstants.AuthenticationMethods.Anonymous));

            var scheme = await GetCookieSchemeAsync();

            await _httpContext.SignInAsync(scheme, principal);
        }
コード例 #10
0
ファイル: CookieManager.cs プロジェクト: formist/LinkMe
 void ICookieManager.UpdateAnonymousCookie(HttpContextBase context, IAnonymousUser user, UserType preferredUserType)
 {
     CreateAnonymousCookie(context, user, preferredUserType);
 }
コード例 #11
0
ファイル: Mappings.cs プロジェクト: formist/LinkMe
 public static AnonymousUserEntity Map(this IAnonymousUser user)
 {
     return(new AnonymousUserEntity {
         id = user.Id
     });
 }