private void Browser_LoadCompleted(object sender, NavigationEventArgs e) { if (this.IsLoaded && this.IsActive && e.Uri.AbsoluteUri.StartsWith(this.redirectUrl)) { this.microsoftAccessInfo = MicrosoftAccessInfo.Parse(e.Uri); this.DialogResult = this.microsoftAccessInfo != null; } }
private void Browser_LoadCompleted(object sender, NavigationEventArgs e) { if (this.IsLoaded && this.IsActive && e.Uri.AbsoluteUri.StartsWith(this.redirectUrl)) { this.microsoftAccessInfo = MicrosoftAccessInfo.Parse(e.Uri); this.DialogResult = this.microsoftAccessInfo != null; } }
public static MicrosoftAccessInfo Parse(Uri uri) { Dictionary <string, string> parameters = uri.ParseFragment(); string accessToken, expiresIn; int expirationInSeconds; MicrosoftAccessInfo accessInfo = null; if (parameters.TryGetValue(AccessTokenParameter, out accessToken) && parameters.TryGetValue(ExpiresInParameter, out expiresIn) && Int32.TryParse(expiresIn, out expirationInSeconds)) { string refreshToken; parameters.TryGetValue(RefreshTokenParameter, out refreshToken); accessInfo = new MicrosoftAccessInfo(accessToken, refreshToken, TimeSpan.FromSeconds(expirationInSeconds)); } return(accessInfo); }
public async Task <MicrosoftAccessInfo> SignInSilentlyAsync() { MicrosoftAccessInfo microsoftAccessInfo = null; var taskCompletionSource = new TaskCompletionSource <object>(); WebBrowser webBrowser = new WebBrowser(); webBrowser.Navigated += (sender, e) => { if (e.Uri.AbsoluteUri.StartsWith(this.RedirectUrl)) { microsoftAccessInfo = MicrosoftAccessInfo.Parse(e.Uri); taskCompletionSource.SetResult(null); } }; webBrowser.Navigate(this.SignInUrl + "&display=none"); await Task.WhenAny(taskCompletionSource.Task, Task.Delay(SignInTimeout)); return(microsoftAccessInfo); }
private async Task SignInAsync() { try { this.ErrorText = null; this.IsWorking = true; this.Status = Resources.SigningIn; this.microsoftAccessInfo = await this.microsoftAccount.SignInSilentlyAsync() ?? await this.microsoftAccount.SignInAsync(); if (this.microsoftAccessInfo == null) { this.Status = Resources.NotSignedIn; } else { this.WebApi = new WebApi(new Credentials(this.serviceConfiguration.PhotosynthUrl, this.microsoftAccessInfo.AccessToken)); UserInfo userInfo = await this.WebApi.GetUserInfoAsync(); if (userInfo != null) { this.Username = userInfo.Username; this.Description = userInfo.Description; } else { await this.SignOutAsync(); this.ErrorText = Resources.NotPhotosynthUser; } } } catch { this.ErrorText = Resources.CouldNotSignIn; } this.UpdateStatus(); }
private async Task SignOutAsync() { try { this.WebApi = null; this.ErrorText = null; this.IsWorking = true; this.Status = Resources.SigningOut; bool signedOut = await this.microsoftAccount.SignOutAsync(); if (signedOut) { this.microsoftAccessInfo = null; this.ClearUserInfo(); } } catch { this.ErrorText = Resources.CouldNotSignOut; } this.UpdateStatus(); }
public static MicrosoftAccessInfo Parse(Uri uri) { Dictionary<string, string> parameters = uri.ParseFragment(); string accessToken, expiresIn; int expirationInSeconds; MicrosoftAccessInfo accessInfo = null; if (parameters.TryGetValue(AccessTokenParameter, out accessToken) && parameters.TryGetValue(ExpiresInParameter, out expiresIn) && Int32.TryParse(expiresIn, out expirationInSeconds)) { string refreshToken; parameters.TryGetValue(RefreshTokenParameter, out refreshToken); accessInfo = new MicrosoftAccessInfo(accessToken, refreshToken, TimeSpan.FromSeconds(expirationInSeconds)); } return accessInfo; }
private async Task SignOutAsync() { try { this.WebApi = null; this.ErrorText = null; this.IsWorking = true; this.Status = Resources.SigningOut; bool signedOut = await this.microsoftAccount.SignOutAsync(); if (signedOut) { this.microsoftAccessInfo = null; this.ClearUserInfo(); } } catch { this.ErrorText = Resources.CouldNotSignOut; } this.UpdateStatus(); }
private async Task SignInAsync() { try { this.ErrorText = null; this.IsWorking = true; this.Status = Resources.SigningIn; this.microsoftAccessInfo = await this.microsoftAccount.SignInSilentlyAsync() ?? await this.microsoftAccount.SignInAsync(); if (this.microsoftAccessInfo == null) { this.Status = Resources.NotSignedIn; } else { this.WebApi = new WebApi(new Credentials(this.serviceConfiguration.PhotosynthUrl, this.microsoftAccessInfo.AccessToken)); UserInfo userInfo = await this.WebApi.GetUserInfoAsync(); if (userInfo != null) { this.Username = userInfo.Username; this.Description = userInfo.Description; } else { await this.SignOutAsync(); this.ErrorText = Resources.NotPhotosynthUser; } } } catch { this.ErrorText = Resources.CouldNotSignIn; } this.UpdateStatus(); }