private async Task AuthenticateAsync() { var scopes = new List <MSAScope> { MSAScope.Basic, MSAScope.Emails, MSAScope.OfflineAccess, MSAScope.SignIn }; string authUri = App.API.RetrieveAuthenticationUri(scopes); WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync( WebAuthenticationOptions.None, new Uri(authUri), new Uri(ApiClient.RedirectUri)); if (result.ResponseStatus == WebAuthenticationStatus.Success) { if (!string.IsNullOrWhiteSpace(result.ResponseData)) { var responseUri = new Uri(result.ResponseData); if (responseUri.LocalPath.StartsWith("/oauth20_desktop.srf", StringComparison.OrdinalIgnoreCase)) { string error = responseUri.GetQueryValue("error"); if (string.IsNullOrWhiteSpace(error)) { string authCode = responseUri.GetQueryValue("code"); MSACredentials msaCredentials = await App.API.ExchangeAuthCodeAsync(authCode); IStorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(CredentialsFileName, CreationCollisionOption.OpenIfExists); await file.WriteTextAsync(JsonConvert.SerializeObject(msaCredentials)); } else { await App.MessageDialogManager.ShowAsync(error); } } } } this.UpdateButtonStates(); }
public static async Task SaveDataAsync <T>(this IStorageFile storageFile, T data) { var json = SerializationService.Json.Serialize(data); await storageFile.WriteTextAsync(json); }