public LiveConnectSession LoadSession(LiveAuthClient authClient) { var appData = IsolatedStorageSettings.ApplicationSettings; LiveConnectSession session = null; if (appData.Values.Count > 0) { session = new LiveConnectSession(authClient); if (appData.Contains(AuthConstants.RefreshToken)) { session.RefreshToken = appData[AuthConstants.RefreshToken] as string; } } return session; }
public async Task<LiveLoginResult> AuthenticateAsync(string redirectUrl, bool silent) { this.redirectUrl = redirectUrl; LiveLoginResult result; if (silent) { result = new LiveLoginResult(LiveConnectSessionStatus.Unknown, null); } else { LiveConnectSession session = new LiveConnectSession(); session.AccessToken = TestAuthClient.FakeAccessToken; session.AuthenticationToken = TestAuthClient.FakeAuthenticationToken; result = new LiveLoginResult(LiveConnectSessionStatus.Connected, session); } return await Task.Factory.StartNew<LiveLoginResult>(() => { return result; }); }
private async System.Threading.Tasks.Task Authenticate() { LiveAuthClient liveIdClient = new LiveAuthClient("URL..."); while (session == null) { // Force a logout to make it easier to test with multiple Microsoft Accounts if (liveIdClient.CanLogout) { liveIdClient.Logout(); } LiveLoginResult result = await liveIdClient.LoginAsync(new[] { "wl.basic" }); if (result.Status == LiveConnectSessionStatus.Connected) { session = result.Session; LiveConnectClient client = new LiveConnectClient(result.Session); LiveOperationResult meResult = await client.GetAsync("me"); MobileServiceUser loginResult = await App.MobileService .LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken); string title = string.Format("Welcome {0}!", meResult.Result["first_name"]); var message = string.Format("You are now logged in - {0}", loginResult.UserId); var dialog = new MessageDialog(message, title); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } else { session = null; var dialog = new MessageDialog("You must log in.", "Login Required"); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } } }
public LiveConnectSession LoadSession(LiveAuthClient authClient) { ApplicationDataContainer appData = ApplicationData.Current.RoamingSettings; LiveConnectSession session = null; if (appData.Values.Count > 0) { session = new LiveConnectSession(authClient); if (appData.Values.ContainsKey(AuthConstants.AccessToken)) { session.AccessToken = appData.Values[AuthConstants.AccessToken] as string; } if (appData.Values.ContainsKey(AuthConstants.AuthenticationToken)) { session.AuthenticationToken = appData.Values[AuthConstants.AuthenticationToken] as string; } if (appData.Values.ContainsKey(AuthConstants.RefreshToken)) { session.RefreshToken = appData.Values[AuthConstants.RefreshToken] as string; } if (appData.Values.ContainsKey(AuthConstants.Expires)) { session.Expires = (DateTimeOffset)appData.Values[AuthConstants.Expires]; } if (appData.Values.ContainsKey(AuthConstants.Scope)) { session.Scopes = LiveAuthClient.ParseScopeString(appData.Values[AuthConstants.Scope] as string); TestAuthClient.Scopes = session.Scopes; } } return(session); }
public async Task <LiveLoginResult> AuthenticateAsync(string redirectUrl, bool silent) { this.redirectUrl = redirectUrl; LiveLoginResult result; if (silent) { result = new LiveLoginResult(LiveConnectSessionStatus.Unknown, null); } else { LiveConnectSession session = new LiveConnectSession(); session.AccessToken = TestAuthClient.FakeAccessToken; session.AuthenticationToken = TestAuthClient.FakeAuthenticationToken; result = new LiveLoginResult(LiveConnectSessionStatus.Connected, session); } return(await Task.Factory.StartNew <LiveLoginResult>(() => { return result; })); }
public static async Task <LiveConnectSessionStatus> LoginAsync() { try { var result = await _authClient.InitializeAsync(_scopes); if (result.Status != LiveConnectSessionStatus.Connected) { result = await _authClient.LoginAsync(_scopes); } if (result.Status == LiveConnectSessionStatus.Connected) { _session = result.Session; } return(result.Status); } catch (LiveAuthException ex) { throw new LiveAuthException(ex.ErrorCode, ex.Message, ex.InnerException); } }
private static async Task <OneDriveClient> OnAuthComplete(LiveAuthClient authClient, AuthResult result) { if (null != result.AuthorizeCode) { try { LiveConnectSession session = await authClient.ExchangeAuthCodeAsync(result.AuthorizeCode); var OneDrive = new OneDriveClient(new LiveConnectClient(session)); return(OneDrive); } catch (LiveAuthException aex) { throw; } catch (LiveConnectException cex) { throw; } } return(null);; }
public RestorePage() { InitializeComponent(); #if GBC SystemTray.GetProgressIndicator(this).Text = AppResources.ApplicationTitle2; #endif //create ad control if (App.HasAds) { AdControl adControl = new AdControl(); ((Grid)(LayoutRoot.Children[0])).Children.Add(adControl); adControl.SetValue(Grid.RowProperty, 2); } this.labelHeight = this.statusLabel.Height; this.session = PhoneApplicationService.Current.State["parameter"] as LiveConnectSession; PhoneApplicationService.Current.State.Remove("parameter"); if (this.session == null) { throw new ArgumentException("Parameter passed to RestorePage must be a LiveConnectSession."); } this.skydriveStack = new List <List <SkyDriveListItem> >(); this.skydriveStack.Add(new List <SkyDriveListItem>()); this.skydriveStack[0].Add(new SkyDriveListItem() { Name = "SkyDrive", SkyDriveID = "me/skydrive", Type = SkyDriveItemType.Folder, ParentID = "" }); this.currentFolderBox.Text = this.skydriveStack[0][0].Name; this.BackKeyPress += SkyDriveImportPage_BackKeyPress; }
public void SyncWithSkyDrive(LiveConnectSession session, Action <BookmarkserviceImportCompletedEventArgs> completedAction) { string syncFilename = AppSettings.GetValueOrDefault(AppSettings.CloudSync.SkyDriveSyncFilename, string.Empty); string syncInternalFilename = AppSettings.GetValueOrDefault(AppSettings.CloudSync.SkyDriveInternalSyncFilename, string.Empty); SyncDirection syncDirection = AppSettings.GetValueOrDefault <SyncDirection>(AppSettings.CloudSync.SyncDirection, SyncDirection.DeviceToCloud); var completedEventArgs = new BookmarkserviceImportCompletedEventArgs(); //if the internal id of the uploaded file is unknown, then check to see if it already exists if (string.IsNullOrEmpty(syncInternalFilename)) { LiveConnectClient client = new LiveConnectClient(session); client.GetCompleted += delegate(object sender, LiveOperationCompletedEventArgs e) { if (e.Error == null) { List <object> data = (List <object>)e.Result["data"]; object oSyncFile = data.Where(x => { return(syncFilename.Equals((x as IDictionary <string, object>)["name"])); }).FirstOrDefault(); if (oSyncFile != null) { syncInternalFilename = (oSyncFile as IDictionary <string, object>)["id"].ToString(); AppSettings.AddOrUpdateValue(AppSettings.CloudSync.SkyDriveInternalSyncFilename, syncInternalFilename); } CoordinateSync(session, syncFilename, syncInternalFilename, completedAction, completedEventArgs); } }; client.GetAsync("/me/skydrive/files"); } else { CoordinateSync(session, syncFilename, syncInternalFilename, completedAction, completedEventArgs); } }
public RestorePage() { InitializeComponent(); this.labelHeight = this.statusLabel.Height; this.session = PhoneApplicationService.Current.State["parameter"] as LiveConnectSession; PhoneApplicationService.Current.State.Remove("parameter"); if (this.session == null) { throw new ArgumentException("Parameter passed to RestorePage must be a LiveConnectSession."); } this.skydriveStack = new List <List <SkyDriveListItem> >(); this.skydriveStack.Add(new List <SkyDriveListItem>()); this.skydriveStack[0].Add(new SkyDriveListItem() { Name = "SkyDrive", SkyDriveID = "me/skydrive", Type = SkyDriveItemType.Folder, ParentID = "" }); this.currentFolderBox.Text = this.skydriveStack[0][0].Name; this.BackKeyPress += SkyDriveImportPage_BackKeyPress; }
private void OnSessionChanged() { LiveConnectSession session = this.AuthClient.Session; //bool isSignedIn = session != null; if (session != null) { Traces.Main_TraceEvent(TraceEventType.Error, 1, "Session changed: Expires: {0}, AccessToken: {1}", session.Expires.ToString("u", System.Globalization.CultureInfo.InvariantCulture), session.AccessToken); if (_RefreshThread == null) { _RefreshThread = new Thread(RefreshThread); _RefreshThread.IsBackground = true; _RefreshThread.Name = "RefreshThread"; _RefreshThread.Start(null); } var handler = SessionChanged; if (handler != null) { handler(session.AccessToken, session.RefreshToken); } } }
public async Task SignIn() { // you should call this from UI thread if (_liveSession == null) { _liveAuth = new LiveAuthClient(_clientId); _liveResult = await _liveAuth.InitializeAsync(_requiredScopes); if (_liveResult.Status != LiveConnectSessionStatus.Connected) { _liveResult = await _liveAuth.LoginAsync(_requiredScopes); } _liveSession = _liveResult.Session; _liveClient = new LiveConnectClient(_liveSession); _liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.AllowCellularAndBattery; } if (_folderId == null) { await GetSkyDriveFolder(); } }
public override void Disconnect() { _session = null; User = null; _liveIdClient.Logout(); }
/// <summary> /// Construct a new LiveConnectSessionChangedEventArgs object. /// </summary> /// <param name="newSession">A new LiveConnectSession instance.</param> public LiveConnectSessionChangedEventArgs(LiveConnectSessionStatus newStatus, LiveConnectSession newSession) { this.Session = newSession; this.Status = newStatus; }
public LiveConnectSession LoadSession(LiveAuthClient authClient) { ApplicationDataContainer appData = ApplicationData.Current.RoamingSettings; LiveConnectSession session = null; if (appData.Values.Count > 0) { session = new LiveConnectSession(authClient); if (appData.Values.ContainsKey(AuthConstants.AccessToken)) { session.AccessToken = appData.Values[AuthConstants.AccessToken] as string; } if (appData.Values.ContainsKey(AuthConstants.AuthenticationToken)) { session.AuthenticationToken = appData.Values[AuthConstants.AuthenticationToken] as string; } if (appData.Values.ContainsKey(AuthConstants.RefreshToken)) { session.RefreshToken = appData.Values[AuthConstants.RefreshToken] as string; } if (appData.Values.ContainsKey(AuthConstants.Expires)) { session.Expires = (DateTimeOffset)appData.Values[AuthConstants.Expires]; } if (appData.Values.ContainsKey(AuthConstants.Scope)) { session.Scopes = LiveAuthClient.ParseScopeString(appData.Values[AuthConstants.Scope] as string); TestAuthClient.Scopes = session.Scopes; } } return session; }
public void Initialize(LiveConnectSession session) { _fileManager.Initialize(_folderName, session); }
public LiveConnectSessionChangedEventArgs(LiveConnectSessionStatus newStatus, LiveConnectSession newSession) { ThrowArgumentException.IfNull(newSession, "newSession"); this.Status = newStatus; this.Session = newSession; }
public async void SignOutAction() { session = null; await Authenticate(); }
// Authenticate the user via Microsoft Account (the default on Windows Phone) // Authentication via Facebook, Twitter or Google ID will be added in a future release. private async Task Authenticate() { prgBusy.IsActive = true; Exception exception = null; try { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TextUserName.Text = "Please wait while we log you in..."; }); LiveAuthClient liveIdClient = new LiveAuthClient(ConfigSecrets.AzureMobileServicesURI); while (session == null) { // Force a logout to make it easier to test with multiple Microsoft Accounts // This code should be commented for the release build //if (liveIdClient.CanLogout) // liveIdClient.Logout(); // Microsoft Account Login LiveLoginResult result = await liveIdClient.LoginAsync(new[] { "wl.basic" }); if (result.Status == LiveConnectSessionStatus.Connected) { session = result.Session; LiveConnectClient client = new LiveConnectClient(result.Session); LiveOperationResult meResult = await client.GetAsync("me"); user = await App.MobileService .LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken); userfirstname = meResult.Result["first_name"].ToString(); userlastname = meResult.Result["last_name"].ToString(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var message = string.Format("Logged in as {0} {1}", userfirstname, userlastname); TextUserName.Text = message; }); // Debugging dialog, make sure it's commented for publishing //var dialog = new MessageDialog(message, "Welcome!"); //dialog.Commands.Add(new UICommand("OK")); //await dialog.ShowAsync(); isLoggedin = true; SetUIState(true); } else { session = null; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { UpdateStatus("You must log in before you can chat in this app.", true); var dialog = new MessageDialog("You must log in.", "Login Required"); dialog.Commands.Add(new UICommand("OK")); dialog.ShowAsync(); }); } } } catch (Exception ex) { exception = ex; } if (exception != null) { UpdateStatus("Something went wrong when trying to log you in.", true); string msg1 = "An error has occurred while trying to sign you in." + Environment.NewLine + Environment.NewLine; // TO DO: Dissect the various potential errors and provide a more appropriate // error message in msg2 for each of them. string msg2 = "Make sure that you have an active Internet connection and try again."; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { new MessageDialog(msg1 + msg2, "Authentication Error").ShowAsync(); }); } prgBusy.IsActive = false; }
public void SaveSession(LiveConnectSession session) { }
private static LiveConnectClient CreateClientForSession(LiveConnectSession session) { var client = new LiveConnectClient(session); return(client); }
public SkyDriveFileDao(LiveConnectSession session) { this.session = session; }
public void SaveSession(LiveConnectSession session) { if (session != null) { ApplicationDataContainer appData = ApplicationData.Current.RoamingSettings; if (appData.Values.ContainsKey(AuthConstants.AccessToken)) { appData.Values.Remove(AuthConstants.AccessToken); } appData.Values.Add(AuthConstants.AccessToken, session.AccessToken); if (appData.Values.ContainsKey(AuthConstants.AuthenticationToken)) { appData.Values.Remove(AuthConstants.AuthenticationToken); } appData.Values.Add(AuthConstants.AuthenticationToken, session.AuthenticationToken); if (!string.IsNullOrEmpty(session.RefreshToken)) { if (appData.Values.ContainsKey(AuthConstants.RefreshToken)) { appData.Values.Remove(AuthConstants.RefreshToken); } appData.Values.Add(AuthConstants.RefreshToken, session.RefreshToken); } if (appData.Values.ContainsKey(AuthConstants.Expires)) { appData.Values.Remove(AuthConstants.Expires); } appData.Values.Add(AuthConstants.Expires, session.Expires); if (appData.Values.ContainsKey(AuthConstants.Scope)) { appData.Values.Remove(AuthConstants.Scope); } appData.Values.Add(AuthConstants.Scope, LiveAuthClient.BuildScopeString(session.Scopes)); TestAuthClient.Scopes = session.Scopes; } }
public OneNoteRepository(LiveConnectSession liveConnectSession) { this.liveConnectSession = liveConnectSession; }
public void SaveSession(LiveConnectSession session) { if (session != null) { var appData = IsolatedStorageSettings.ApplicationSettings; if (!string.IsNullOrEmpty(session.RefreshToken)) { if (appData.Contains(AuthConstants.RefreshToken)) { appData.Remove(AuthConstants.RefreshToken); } appData.Add(AuthConstants.RefreshToken, session.RefreshToken); } appData.Save(); } }
// Autentica al usuario a través de una cuenta de Microsoft (cuenta por defecto en Windows Phone) // Autenticación a través de Facebook, Twitter o Google se agregará en una versión futura. private async Task Authenticate() { prgBusy.IsActive = true; Exception exception = null; try { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TextUserName.Text = "Por favor, espera mientras inicias sesión..."; }); LiveAuthClient liveIdClient = new LiveAuthClient(Configuracion.AzureMobileServicesURI); while (session == null) { // Inicio de sesión en Microsoft Account LiveLoginResult result = await liveIdClient.LoginAsync(new[] { "wl.basic" }); if (result.Status == LiveConnectSessionStatus.Connected) { session = result.Session; LiveConnectClient client = new LiveConnectClient(result.Session); LiveOperationResult meResult = await client.GetAsync("me"); user = await App.MobileService .LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken); userfirstname = meResult.Result["first_name"].ToString(); userlastname = meResult.Result["last_name"].ToString(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var message = string.Format("Autenticado como: {0} {1}", userfirstname, userlastname); TextUserName.Text = message; }); isLoggedin = true; SetUIState(true); } else { session = null; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { UpdateStatus("Debes de iniciar sesión antes de que puedas usar esta aplicación.", true); var dialog = new MessageDialog("Debes iniciar sesión.", "Inicio de sesión requerido."); dialog.Commands.Add(new UICommand("OK")); dialog.ShowAsync(); }); } } } catch (Exception ex) { exception = ex; } if (exception != null) { UpdateStatus("Algo salió mal al tratar de iniciar sesión.", true); string msg1 = "Se ha producido un error al intentar iniciar sesión." + Environment.NewLine + Environment.NewLine; // TO DO: Dividir los distintos errores y ofrecer un adecuado // Mensaje de error en msg2 para cada uno. string msg2 = "Asegúrate de que tienes una conexión a Internet activa y vuelve a intentarlo."; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { new MessageDialog(msg1 + msg2, "Error de Autenticación").ShowAsync(); }); } prgBusy.IsActive = false; }
/// <summary> /// Provider class to access SkyDrive contents. /// </summary> /// <param name="session">A live connect session which will be used to retrieve cloud content.</param> public SkyDriveProvider(LiveConnectSession session) : base("SkyDrive", SupportedDrive.SkyDrive, RootDirectory) { Init(session); }