Exemple #1
0
        private static User GetUser(ClaimsIdentity ident, string loginString, WutNuContext wutContext)
        {
            var oid  = ident.Claims.SingleOrDefault(c => c.Type == CustomClaimTypes.ObjectIdentifier).Value;
            var user = wutContext.Users.SingleOrDefault(u => u.UserOID == oid);

            if (user == null)
            {
                user = new User
                {
                    UserOID      = oid,
                    PrimaryEmail = loginString,
                    ApiKey       = SiteUtils.GenApiKey()
                };

                user = wutContext.Users.Add(user);

                //update any existing user assignments with the new userid
                var assignments = wutContext.UserAssignments.Where(u => u.UserEmail == user.PrimaryEmail && u.UserId == null);
                assignments.ForEach(a =>
                {
                    a.UserId = user.UserId;
                });

                wutContext.SaveChanges();
            }
            return(user);
        }
Exemple #2
0
        public UserPoco ResetApiKey(UserPoco data)
        {
            data.UserId = UserId;
            data.ApiKey = SiteUtils.GenApiKey();

            return(_repo.UpdateUser(data));
        }
Exemple #3
0
        private static User GetUser(ClaimsIdentity ident, string loginString, WutNuContext wutContext)
        {
            //have to check source to get an object ID: AAD is using OID, B2C is using nameidentifier
            string oid = null;

            var issuer = ident.Claims.First().Issuer;

            if (issuer.IndexOf("b2clogin.com") > -1)
            {
                oid = ident.GetClaim(ClaimTypes.NameIdentifier);
                if (!ident.HasClaim(CustomClaimTypes.ObjectIdentifier))
                {
                    ident.AddClaim(new Claim(CustomClaimTypes.ObjectIdentifier, oid));
                }
            }
            else
            {
                oid = ident.GetClaim(CustomClaimTypes.ObjectIdentifier);
            }

            var user = wutContext.Users.SingleOrDefault(u => u.UserOID == oid);

            if (user == null)
            {
                user = new User
                {
                    UserOID      = oid,
                    PrimaryEmail = loginString,
                    ApiKey       = SiteUtils.GenApiKey()
                };

                user = wutContext.Users.Add(user);

                //update any existing user assignments with the new userid
                var assignments = wutContext.UserAssignments.Where(u => u.UserEmail == user.PrimaryEmail && u.UserId == null);
                assignments.ForEach(a =>
                {
                    a.UserId = user.UserId;
                });
            }

            user.iss = ident.GetClaim("iss");
            user.idp = ident.GetClaim(CustomClaimTypes.IdentityProvider);

            wutContext.SaveChanges();

            return(user);
        }