public static Client15Connector CreateClientConnector(string siteUrl, PSCredential credential, SwitchParameter cloudCredential, AppLog appLog) { Client15Connector clientConnector = new Client15Connector(siteUrl); if (credential != null) { if (cloudCredential.IsPresent) { clientConnector.SetCredentialsForCloud(credential.UserName, credential.Password, (message) => { appLog.WriteVerbose(message); } ); } else { clientConnector.SetCredentialsForOnPrem(credential.UserName, credential.Password); } } else { if (cloudCredential.IsPresent) { throw new InvalidOperationException( "The -CloudCredential switch cannot be used without specifying a credential object"); } } return(clientConnector); }
public void SetCredentials(Client15Connector connector) { switch (this.AuthenticationMode) { case AuthenticationMode.WindowsCredentials: return; case AuthenticationMode.FormsAuthentication: connector.SetCredentialsForOnPrem(this.UserName, LoginInfo.MakeSecureString(this.Password)); return; case AuthenticationMode.CloudAuthentication: connector.SetCredentialsForCloud(this.UserName, LoginInfo.MakeSecureString(this.Password)); return; default: throw new NotImplementedException("Cloud login not implemented"); } }