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); }
AnonymousContact IAnonymousRepository.GetContact(IAnonymousUser user, ContactDetails contactDetails) { using (var dc = CreateContext().AsReadOnly()) { return(GetContactByDetails(dc, user.Id, contactDetails)); } }
/// <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)); }
/// <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); }
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); }
/// <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)); }
/// <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); }
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(); } }
/// <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); }
void ICookieManager.UpdateAnonymousCookie(HttpContextBase context, IAnonymousUser user, UserType preferredUserType) { CreateAnonymousCookie(context, user, preferredUserType); }
public static AnonymousUserEntity Map(this IAnonymousUser user) { return(new AnonymousUserEntity { id = user.Id }); }