public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

      #warning first we have to setup connection info and create a session
            var instanceUrl = "http://my.site.com";

            using (var credentials = new SecureStringPasswordProvider("login", "password"))
                using (
                    var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
                                  .Credentials(credentials)
                                  .WebApiVersion("v1")
                                  .DefaultDatabase("web")
                                  .DefaultLanguage("en")
                                  .BuildSession())
                {
                    // In order to fetch some data we have to build a request
                    var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home")
                                  .AddFieldsToRead("text")
                                  .AddScope(ScopeType.Self)
                                  .Build();

                    // And execute it on a session asynchronously
                    var response = await session.ReadItemAsync(request);

                    // Now that it has succeeded we are able to access downloaded items
                    ISitecoreItem item = response[0];

                    // And content stored it its fields
                    string fieldContent = item["text"].RawValue;

                    UIAlertView alert = new UIAlertView("Sitecore SDK Demo", fieldContent, null, "Ok", null);
                    alert.Show();
                }
        }
        public void TestPasswordStorageAllowsNullPassword()
        {
            const string login    = "******";
            const string password = null;

            using (var passwordStorage = new SecureStringPasswordProvider(login, password))
            {
                Assert.AreEqual(login, passwordStorage.Username);
                Assert.AreEqual(password, passwordStorage.Password);
            }
        }
        public void TestPasswordStorageAllowsWhitespaceLogin()
        {
            const string login    = "******";
            const string password = "******";

            using (var passwordStorage = new SecureStringPasswordProvider(login, password))
            {
                Assert.AreEqual(login, passwordStorage.Username);
                Assert.AreEqual(password, passwordStorage.Password);
            }
        }
        public void TestPasswordStorageReturnsSameValues()
        {
            const string login    = "******";
            const string password = "******";

            using (var passwordStorage = new SecureStringPasswordProvider(login, password))
            {
                Assert.AreEqual(login, passwordStorage.Username);
                Assert.AreEqual(password, passwordStorage.Password);
            }
        }
        private async void Authenticate()
        {
            var instanceUrl = this.instanceUrlField.Text;
            var login       = this.loginField.Text;
            var password    = this.passwordField.Text;
            var site        = this.siteField.Text;

            if (string.IsNullOrEmpty(instanceUrl))
            {
                Toast.MakeText(this, "Please provide instance url", ToastLength.Long).Show();
                return;
            }

            if (string.IsNullOrEmpty(login) && string.IsNullOrEmpty(password))
            {
                Toast.MakeText(this, "Please provide both login and password", ToastLength.Long).Show();
                return;
            }

            try
            {
                using (var credentials = new SecureStringPasswordProvider(login, password))
                    using (var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
                                         .Credentials(credentials)
                                         .Site(site)
                                         .BuildReadonlySession())
                    {
                        this.SetProgressBarIndeterminateVisibility(true);

                        bool response = await session.AuthenticateAsync();

                        this.SetProgressBarIndeterminateVisibility(false);
                        if (response)
                        {
                            DialogHelper.ShowSimpleDialog(this, "Success", "This user exists");
                        }
                        else
                        {
                            DialogHelper.ShowSimpleDialog(this, "Failed", "This user doesn't exist");
                        }
                    }
            }
            catch (System.Exception exception)
            {
                this.SetProgressBarIndeterminateVisibility(false);

                var title = this.GetString(Resource.String.text_error);
                DialogHelper.ShowSimpleDialog(this, title, exception.Message);
            }
        }
        private static void Main(string[] args)
        {
            using (var demoCredentials = new SecureStringPasswordProvider("admin", "b"))
            {
                string instanceUrl = "http://mobiledev1ua1.dk.sitecore.net:7220";

                using
                (
                    var session =
                        SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
                        .Credentials(demoCredentials)
                        .Site("/sitecore/shell")
                        .DefaultDatabase("web")
                        .DefaultLanguage("en")
                        .MediaLibraryRoot("/sitecore/media library")
                        .MediaPrefix("~/media/")
                        .DefaultMediaResourceExtension("ashx")
                        .BuildReadonlySession()
                )
                {
                    var request =
                        ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home")
                        .AddScope(ScopeType.Self)
                        .Payload(PayloadType.Content)
                        .Build();
                    var readHomeItemTask = session.ReadItemAsync(request);

                    // @adk : cannot use "await" in main
                    Task.WaitAll(readHomeItemTask);

                    ScItemsResponse items     = readHomeItemTask.Result;
                    string          fieldText = items[0]["Text"].RawValue;

                    Console.BackgroundColor = ConsoleColor.White;
                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.Clear();

                    Console.WriteLine("Home Item Text");
                    Console.WriteLine();
                    Console.WriteLine(fieldText);

                    Console.ReadKey();
                }
            }
        }
        public void TestPasswordStorageCopyReturnsSameValues()
        {
            const string login    = "******";
            const string password = "******";

            using (var passwordStorage = new SecureStringPasswordProvider(login, password))
            {
                Assert.AreEqual(login, passwordStorage.Username);
                Assert.AreEqual(password, passwordStorage.Password);

                using (var passwordStorageCopy = passwordStorage.CredentialsShallowCopy())
                {
                    Assert.AreNotSame(passwordStorage, passwordStorageCopy);

                    Assert.AreEqual(login, passwordStorageCopy.Username);
                    Assert.AreEqual(password, passwordStorageCopy.Password);
                }
            }
        }
        public ISitecoreWebApiSession GetSession()
        {
            using
            (
                var credentials =
                    new SecureStringPasswordProvider(
                        this.instanceLogin,
                        this.instancePassword)
            )
            {
                var result = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(this.instanceUrl)
                             .Credentials(credentials)
                             .Site(this.instanceSite)
                             .DefaultDatabase(this.instanceDataBase)
                             .DefaultLanguage(this.instanceLanguage)
                             .BuildSession();

                return(result);
            }
        }
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            string instanceUrl = "http://my.site.com";

            using (var credentials = new SecureStringPasswordProvider("login", "password"))
                using (
                    var session =
                        SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
                        .Credentials(credentials)
                        .DefaultDatabase("web")
                        .DefaultLanguage("en")
                        .MediaLibraryRoot("/sitecore/media library")
                        .MediaPrefix("~/media/")
                        .DefaultMediaResourceExtension("ashx")
                        .BuildReadonlySession())
                {
                    var request =
                        ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home")
                        .AddScope(ScopeType.Self)
                        .Payload(PayloadType.Content)
                        .Build();

                    ScItemsResponse items = await session.ReadItemAsync(request);

                    string fieldContent = items[0]["Text"].RawValue;

                    string itemName = "Home Item Text";

                    var dialogBuilder = new AlertDialog.Builder(this);
                    dialogBuilder.SetTitle(itemName);
                    dialogBuilder.SetMessage(fieldContent);
                    dialogBuilder.SetPositiveButton("OK", (object sender, DialogClickEventArgs e) =>
                    {
                    });

                    dialogBuilder.Create().Show();
                }
        }
Ejemplo n.º 10
0
        private ISitecoreWebApiSession GetSession(string userName = "", string password = "")
        {
            if (string.IsNullOrEmpty(userName))
            {
                userName = Constants.Sitecore.SitecoreUserName;
                password = Constants.Sitecore.SitecorePassword;
            }

            using (IWebApiCredentials credentials = new SecureStringPasswordProvider(userName, password))
            {
                ISitecoreWebApiSession session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(Constants.Sitecore.RestBaseUrl)
                                                 .Credentials(credentials)
                                                 .Site(Constants.Sitecore.SitecoreShellSite)
                                                 .DefaultDatabase(Constants.Sitecore.SitecoreDefaultDatabase)
                                                 .DefaultLanguage(Constants.Sitecore.SitecoreDefaultLanguage)
                                                 .MediaLibraryRoot(Constants.Sitecore.SitecoreMediaLibraryRoot)
                                                 .MediaPrefix(Constants.Sitecore.SitecoreMediaPrefix)
                                                 .DefaultMediaResourceExtension(Constants.Sitecore.SitecoreDefaultMediaResourceExtension)
                                                 .BuildSession();
                return(session);
            }
        }
Ejemplo n.º 11
0
        private async void SendAuthRequest()
        {
            try
            {
                using (var credentials = new SecureStringPasswordProvider(this.loginField.Text, this.passwordField.Text))
                    using
                    (
                        var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(this.urlField.Text)
                                      .Credentials(credentials)
                                      .Site(this.siteField.Text)
                                      .BuildReadonlySession()
                    )
                    {
                        this.ShowLoader();

                        bool response = await session.AuthenticateAsync();

                        if (response)
                        {
                            AlertHelper.ShowLocalizedAlertWithOkOption("Message", "This user exist");
                        }
                        else
                        {
                            AlertHelper.ShowLocalizedAlertWithOkOption("Message", "This user not exist");
                        }
                    }
            }
            catch (Exception e)
            {
                AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
            }
            finally
            {
                BeginInvokeOnMainThread(delegate
                {
                    this.HideLoader();
                });
            }
        }