Beispiel #1
0
        public static WebUserManager Create(IdentityFactoryOptions <WebUserManager> options, IOwinContext context)
        {
            var manager = new WebUserManager(new WebUserStore(context.Get <DesiOfferEntities>()));

            // Configure validation logic for usernames
            manager.UserLockoutEnabledByDefault = true;
            return(manager);
        }
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(WebUserManager manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here

            userIdentity.AddClaim(new Claim(CustomClaimTypes.Permission, Permissions.ProductMakeOffer));
            userIdentity.AddClaim(new Claim(CustomClaimTypes.CustomerId, Id));
            return(userIdentity);
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            using (WebUserManager _repo = context.OwinContext.Get <WebUserManager>())
            {
                WebUser user = await _repo.FindAsync(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim("sub", context.UserName));
            identity.AddClaim(new Claim("role", "user"));

            context.Validated(identity);
        }
Beispiel #4
0
 public WebSignInManager(WebUserManager userManager, IAuthenticationManager authenticationManager)
     : base(userManager, authenticationManager)
 {
 }