-// -----------------------------------------------------------------------
-// <copyright file="PithosAccount.cs" company="GRNet">
-// Copyright 2011-2012 GRNET S.A. All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or
-// without modification, are permitted provided that the following
-// conditions are met:
-//
-// 1. Redistributions of source code must retain the above
-// copyright notice, this list of conditions and the following
-// disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
-// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-// The views and conclusions contained in the software and
-// documentation are those of the authors and should not be
-// interpreted as representing official policies, either expressed
-// or implied, of GRNET S.A.
+#region
+/* -----------------------------------------------------------------------
+ * <copyright file="PithosAccount.cs" company="GRNet">
+ *
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ * </copyright>
+ * -----------------------------------------------------------------------
+ */
+#endregion
// </copyright>
// -----------------------------------------------------------------------
using System.IO;
+using System.Reflection;
+using Pithos.Client.WPF.Preferences;
+using Pithos.Client.WPF.Properties;
using Pithos.Network;
using log4net;
/// </summary>
public static class PithosAccount
{
- private static readonly ILog Log = LogManager.GetLogger(typeof(PithosAccount));
+ private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Asynchronously retrieves PITHOS credentials
/// </summary>
/// <param name="loginUrl">URL to retrieve the account info from PITHOS. Must end with =</param>
/// <returns>The credentials wrapped in a Task</returns>
- public static Task<NetworkCredential> RetrieveCredentials(string loginUrl)
+ public static NetworkCredential RetrieveCredentials(string loginUrl,string accountName=null)
{
Contract.Requires(Uri.IsWellFormedUriString(loginUrl, UriKind.Absolute));
if (!Uri.IsWellFormedUriString(loginUrl, UriKind.Absolute))
throw new ArgumentException("The pithosSite parameter must be a valid absolute URL", "loginUrl");
- int port = GetFreePort();
+ //int port = GetFreePort();
//TODO:Force logout here to take care of existing cookies
- var listenerUrl = String.Format("http://127.0.0.1:{0}/", port);
+ //var listenerUrl = String.Format("http://127.0.0.1:{0}", port);
+ var listenerUrl = "pithos://127.0.0.1";
- var receiveCredentials = ListenForRedirectAsync(port);
+ //var receiveCredentials = ListenForRedirectAsync(port);
- var uriBuilder=new UriBuilder(loginUrl);
- uriBuilder.Query="next=" + listenerUrl;
+ //var logoutUrl = loginUrl.Replace("login", "im/logout");
+ //var logoutProcess=Process.Start(logoutUrl);
+ //TaskEx.Delay(2000).Wait();
+ var uriBuilder = new UriBuilder(loginUrl)
+ {
+ Query = String.Format("next={0}&force=", listenerUrl)
+ };
var retrieveUri = uriBuilder.Uri;
+
+ var logoutUrl= (from server in Settings.Default.Servers
+ where server.LoginUri == loginUrl
+ select new Uri(server.LogoutUri)).FirstOrDefault();
+
+
+
+ var browser = new LoginView(retrieveUri,logoutUrl,accountName);
+ if (true == browser.ShowDialog())
+ {
+ return new NetworkCredential(browser.Account, browser.Token);
+ }
+ return null;
+
+/*
+
Log.InfoFormat("[RETRIEVE] Open Browser at {0}", retrieveUri);
Process.Start(retrieveUri.ToString());
return receiveCredentials;
+*/
}
/*