public static async Task<bool?> LoginAsync(bool logout) { try { var _Client = new Microsoft.Live.LiveAuthClient() { Theme = Microsoft.Live.ThemeType.Light }; if (logout && _Client.CanLogout) _Client.Logout(); LoginResult = await _Client.LoginAsync(new string[] { "wl.signin", "wl.basic", "wl.emails", "wl.skydrive", "wl.skydrive_update" }); if (LoginResult.Status != Microsoft.Live.LiveConnectSessionStatus.Connected) return false; Client = new Microsoft.Live.LiveConnectClient(LoginResult.Session); var _MeResult = (await Client.GetAsync("me")).Result; dynamic _PhotoResult = (await Client.GetAsync("me/picture")).Result; var _PhotoLocation = new Uri(_PhotoResult.location, UriKind.Absolute); User = new LiveId(_MeResult, _PhotoLocation); return true; } catch (Exception) { System.Diagnostics.Debugger.Break(); return null; } }
public async Task<bool?> LoginAsync(bool logout) { try { var client = new Microsoft.Live.LiveAuthClient() { Theme = Microsoft.Live.ThemeType.Light }; // logout var can = client.CanLogout; if (logout && can) client.Logout(); // prompt var scope = new string[] { "wl.basic", "wl.emails", "wl.skydrive", "wl.photos", "wl.calendars" }; LoginResult = await client.LoginAsync(scope); // and? if (LoginResult.Status != Microsoft.Live.LiveConnectSessionStatus.Connected) return false; // get profile Client = new Microsoft.Live.LiveConnectClient(LoginResult.Session); var result = (await Client.GetAsync("me")).Result; // get photo dynamic photo = (await Client.GetAsync("me/picture")).Result; var path = new Uri(photo.location, UriKind.Absolute); // persist User = new LiveId(result, path); return true; } catch (Exception) { System.Diagnostics.Debugger.Break(); return null; } }
private async Task <string> GetNewAuthToken(bool silent, ISettings settings) { var liveIdClient = new Microsoft.Live.LiveAuthClient(Constants.VercorsServiceUri); // add "wl.emails" in the scope to be able to access user email address // (readable in the meResult object) Microsoft.Live.LiveLoginResult result; if (silent) { result = await liveIdClient.InitializeAsync(new[] { "wl.signin", "wl.offline_access" }); } else { result = await liveIdClient.LoginAsync(new[] { "wl.signin", "wl.offline_access" }); } if (result.Status == Microsoft.Live.LiveConnectSessionStatus.Connected && result.Session != null && !string.IsNullOrEmpty(result.Session.AuthenticationToken)) { settings.SetValue(CoreSettings.SyncAuthToken, result.Session.AuthenticationToken); var client = new Microsoft.Live.LiveConnectClient(result.Session); #if !BACKGROUND client.GetAsync("me").ContinueWith(r => { var me = r.Result; string firstName = me.Result["first_name"] as string; string lastName = me.Result["last_name"] as string; settings.SetValue(CoreSettings.SyncFirstName, firstName ?? string.Empty); settings.SetValue(CoreSettings.SyncLastName, lastName ?? string.Empty); }, TaskScheduler.Default); #endif return(result.Session.AuthenticationToken); } return(null); }
private async Task <string> GetResourceId(string parentId, string folderName, string resourceType) { var result = await _lcClient.GetAsync(parentId + filesSuffix); var data = (IList <object>)result.Result["data"]; foreach (IDictionary <string, object> file in data) { try { var name = (string)file["name"]; var type = (string)file["type"]; if (name.Equals(folderName, StringComparison.InvariantCultureIgnoreCase) && type.Equals(resourceType, StringComparison.InvariantCultureIgnoreCase)) { var id = (string)file["id"]; return(id); } } catch { } } return(string.Empty); }