private async void AuthenticationBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e) { // Get the currently displayed URL and show it in the textbox CurrentUrlTextBox.Text = e.Url.ToString(); // Check if the current URL contains the authorization token AuthorizationCodeTextBox.Text = OneDriveApi.GetAuthorizationTokenFromUrl(e.Url.ToString()); // Verify if an authorization token was successfully extracted if (!string.IsNullOrEmpty(AuthorizationCodeTextBox.Text)) { // Get an access token based on the authorization token that we now have await OneDriveApi.GetAccessToken(); if (OneDriveApi.AccessToken != null) { // Show the access token information in the textboxes AccessTokenTextBox.Text = OneDriveApi.AccessToken.AccessToken; RefreshTokenTextBox.Text = OneDriveApi.AccessToken.RefreshToken; AccessTokenValidTextBox.Text = OneDriveApi.AccessTokenValidUntil.HasValue ? OneDriveApi.AccessTokenValidUntil.Value.ToString("dd-MM-yyyy HH:mm:ss") : "Not valid"; // Store the refresh token in the AppSettings so next time you don't have to log in anymore _configuration.AppSettings.Settings["OneDriveApiRefreshToken"].Value = RefreshTokenTextBox.Text; _configuration.Save(ConfigurationSaveMode.Modified); return; } } // If we're on this page, but we didn't get an authorization token, it means that we just signed out, proceed with signing in again if (CurrentUrlTextBox.Text.StartsWith(OneDriveApi.SignoutUri)) { var authenticateUri = OneDriveApi.GetAuthenticationUri(); AuthenticationBrowser.Navigate(authenticateUri); } }
private async void AuthenticationBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e) { // Get the currently displayed URL and show it in the textbox CurrentUrlTextBox.Text = e.Url.ToString(); // WebRequest request = WebRequest.Create("https://login.live.com/oauth20_authorize.srf?pretty=false&client_id=233d9409-2bc0-404a-8f1e-c122a81615dc&scope=wl.basic+wl.signin+wl.skydrive&response_type=code&redirect_uri=https:%2f%2flogin.microsoftonline.com%2fcommon%2foauth2%2fnativeclient"); // WebResponse response = request.GetResponse(); // Check if the current URL contains the authorization token AuthorizationCodeTextBox.Text = OneDriveApi.GetAuthorizationTokenFromUrl(e.Url.ToString()); // Verify if an authorization token was successfully extracted if (!string.IsNullOrEmpty(AuthorizationCodeTextBox.Text)) { // Get an access token based on the authorization token that we now have await OneDriveApi.GetAccessToken(); if (OneDriveApi.AccessToken != null) { // Show the access token information in the textboxes AccessTokenTextBox.Text = OneDriveApi.AccessToken.AccessToken; RefreshTokenTextBox.Text = OneDriveApi.AccessToken.RefreshToken; AccessTokenValidTextBox.Text = OneDriveApi.AccessTokenValidUntil.HasValue ? OneDriveApi.AccessTokenValidUntil.Value.ToString("dd-MM-yyyy HH:mm:ss") : "Not valid"; // Store the refresh token in the AppSettings so next time you don't have to log in anymore _configuration.AppSettings.Settings["OneDriveApiRefreshToken"].Value = RefreshTokenTextBox.Text; _configuration.Save(ConfigurationSaveMode.Modified); return; } } // If we're on this page, but we didn't get an authorization token, it means that we just signed out, proceed with signing in again if (CurrentUrlTextBox.Text.StartsWith(OneDriveApi.SignoutUri)) { var authenticateUri = OneDriveApi.GetAuthenticationUri(); AuthenticationBrowser.Navigate(authenticateUri); } }