public ScApiSession( ISessionConfig config, IWebApiCredentials credentials, IMediaLibrarySettings mediaSettings, ItemSource defaultSource = null, HttpMessageHandler httpMessageHandler = null) { if (null == config) { throw new ArgumentNullException("ScApiSession.config cannot be null"); } this.sessionConfig = config.SessionConfigShallowCopy(); this.requestMerger = new UserRequestMerger(this.sessionConfig, defaultSource); if (null != credentials) { this.credentials = credentials.CredentialsShallowCopy(); } if (null != mediaSettings) { this.mediaSettings = mediaSettings.MediaSettingsShallowCopy(); } this.httpClient = httpMessageHandler == null ? new HttpClient() : new HttpClient(httpMessageHandler); }
public ScApiSession( ISessionConfig config, IWebApiCredentials credentials, IMediaLibrarySettings mediaSettings, ItemSource defaultSource = null) { if (null == config) { throw new ArgumentNullException("ScApiSession.config cannot be null"); } this.sessionConfig = config.SessionConfigShallowCopy(); this.requestMerger = new UserRequestMerger(this.sessionConfig, defaultSource); if (null != credentials) { this.credentials = credentials.CredentialsShallowCopy(); } if (null != mediaSettings) { this.mediaSettings = mediaSettings.MediaSettingsShallowCopy(); } this.httpClient = new HttpClient(); }
public static bool IsAnonymousSession(IWebApiCredentials credentials) { if (!IsValidCredentials(credentials)) { return(false); } return(string.IsNullOrWhiteSpace(credentials.Username)); }
public static bool IsAnonymousSession(IWebApiCredentials credentials) { if (!IsValidCredentials(credentials)) { return false; } return string.IsNullOrWhiteSpace(credentials.Username); }
public ScTestApiSession( ISessionConfig config, IWebApiCredentials credentials, IMediaLibrarySettings mediaSettings, ItemSource defaultSource = null) : base(config, credentials, mediaSettings, defaultSource) { this.GetPublicKeyInvocationsCount = 0; }
public IBaseSessionBuilder Credentials(IWebApiCredentials credentials) { // @adk : won't be invoked more than once. // No validation needed. BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Username, this.GetType().Name + ".Credentials.Username"); BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Password, this.GetType().Name + ".Credentials.Password"); this.credentials = credentials.CredentialsShallowCopy(); return(this); }
public void SetUp() { this.credentials = new WebApiCredentialsPOD( "alex.fergusson", "man u is a champion"); this.mediaSettings = new MediaLibrarySettings( "/sitecore/media library", "ashx", "~/media/"); this.localhostConnection = new SessionConfig("localhost"); }
private async Task <ISitecoreWebApiSession> GetSession() { Models.Settings settings = await _settingsRepository.GetWithFallback(); using (IWebApiCredentials credentials = DependencyService.Get <ICustomSecureStringPasswordProvider> ().Login(settings.SitecoreUserName, settings.SitecorePassword)) { { ISitecoreWebApiSession session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(settings.RestBaseUrl) .Credentials(credentials) .Site(settings.SitecoreShellSite) .DefaultDatabase(settings.SitecoreDefaultDatabase) .DefaultLanguage(settings.SitecoreDefaultLanguage) .MediaLibraryRoot(settings.SitecoreMediaLibraryRoot) .MediaPrefix(settings.SitecoreMediaPrefix) .DefaultMediaResourceExtension(settings.SitecoreDefaultMediaResourceExtension) .BuildSession(); return(session); } } }
public void TestAuthenticatedSessionShouldBeCreatedByTheBuilder() { IWebApiCredentials credentials = this.adminCredentials; var builder = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost("sitecore.net") .Credentials(credentials) .WebApiVersion("v1") .DefaultDatabase("web") .DefaultLanguage("en") .Site("/sitecore/shell") .MediaLibraryRoot("/sitecore/media library") .DefaultMediaResourceExtension("ashx"); ISitecoreWebApiSession session = builder.BuildSession(); Assert.IsNotNull(session); var roSession = builder.BuildReadonlySession(); Assert.IsNotNull(roSession); }
public static bool IsValidCredentials(IWebApiCredentials credentials) { if (null == credentials) { return(false); } else if (string.IsNullOrWhiteSpace(credentials.Username)) { // anonymous session return(true); } else { if (string.IsNullOrEmpty(credentials.Password)) { return(false); } else { return(true); } } }
public static bool IsValidCredentials(IWebApiCredentials credentials) { if (null == credentials) { return false; } else if (string.IsNullOrWhiteSpace(credentials.Username)) { // anonymous session return true; } else { if (string.IsNullOrEmpty(credentials.Password)) { return false; } else { return true; } } }
public void TearDown() { this.mediaSettings = null; this.credentials = null; this.localhostConnection = null; }
public IBaseSessionBuilder Credentials(IWebApiCredentials credentials) { // @adk : won't be invoked more than once. // No validation needed. BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Username, this.GetType().Name + ".Credentials.Username"); BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Password, this.GetType().Name + ".Credentials.Password"); this.credentials = credentials.CredentialsShallowCopy(); return this; }