Ejemplo n.º 1
0
        public static ClientContext GetContext(string webUrl, string username)
        {
            string   userName = username;
            string   password = "";
            UserPass userinfo = Helpers.CredentialHelper.GetCredentials("zalodevcreds");

            if (userinfo == null)
            {
                Console.WriteLine("User: "******"\r\n");
                password = GetPassword();
                Helpers.CredentialHelper.SetCredentials(new UserPass()
                {
                    UserName = username, Password = password
                }, "zalodevcreds");
            }
            else
            {
                password = userinfo.Password;
                username = userinfo.UserName;
            }

            var secure = new SecureString();

            foreach (char c in password)
            {
                secure.AppendChar(c);
            }



            ClientContext ctx = new ClientContext(webUrl);

            ctx.Credentials = ctx.Credentials = new SharePointOnlineCredentials(userName, secure);
            return(ctx);
        }
Ejemplo n.º 2
0
        public static bool SetCredentials(UserPass up, string CredentialName)
        {
            var cm = new Credential {
                Target = CredentialName, PersistanceType = PersistanceType.Enterprise, Username = up.UserName, Password = up.Password
            };

            return(cm.Save());
        }
Ejemplo n.º 3
0
        public static UserPass GetCredentials(string CredentialName)
        {
            var cm = new Credential {
                Target = CredentialName
            };

            if (!cm.Exists())
            {
                return(null);
            }

            cm.Load();
            var up = new UserPass(cm);

            return(up);
        }