Example #1
0
        public static User BuildUser(this ClaimsPrincipal claimsPrincipal)
        {
            var    userClaims = claimsPrincipal.BuildClaims();
            var    claimSub   = userClaims.FirstOrDefault(c => c.Type == Jwt.Constants.UserClaims.Subject);
            var    claimName  = userClaims.FirstOrDefault(c => c.Type == Jwt.Constants.UserClaims.Name);
            string sub        = claimSub == null ? null : claimSub.Value;
            string name       = claimName == null ? null : claimName.Value;
            var    user       = User.Create(name, sub);

            user.UpdateClaims(userClaims);
            return(user);
        }
Example #2
0
        public static OAuthUser BuildOAuthUser(this ClaimsPrincipal claimsPrincipal, string scheme)
        {
            var    userClaims = claimsPrincipal.BuildClaims();
            var    claimSub   = userClaims.FirstOrDefault(c => c.Name == SimpleIdServer.Jwt.Constants.UserClaims.Subject);
            var    claimName  = userClaims.FirstOrDefault(c => c.Name == SimpleIdServer.Jwt.Constants.UserClaims.Name);
            string sub        = claimSub == null ? null : claimSub.Value;
            string name       = claimName == null ? null : claimName.Value;
            var    user       = OAuthUser.Create(name, null);

            if (claimSub != null)
            {
                userClaims.Remove(claimSub);
                userClaims.Add(new Common.Domains.UserClaim(SimpleIdServer.Jwt.Constants.UserClaims.Subject, user.Id));
            }

            user.UpdateClaims(userClaims);
            user.AddExternalAuthProvider(scheme, sub);
            return(user);
        }