private Task <bool> ShowWebView() { var tcs = new TaskCompletionSource <bool>(); var auth = new OAuth2Authenticator(OneDriveAuthenticationConstants.MSA_CLIENT_ID, string.Join(",", OneDriveAuthenticationConstants.Scopes), new Uri(GetAuthorizeUrl()), new Uri(OneDriveAuthenticationConstants.RETURN_URL)); auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { OAuthErrorHandler.ThrowIfError(eventArgs.Account.Properties); authenticationResponseValues = eventArgs.Account.Properties; tcs.SetResult(true); } }; var intent = auth.GetUI(Application.Context); intent.SetFlags(ActivityFlags.NewTask); Application.Context.StartActivity(intent); return(tcs.Task); }
public void ValidateError_NoDescription() { var errorMessage = "This is an error."; var responseValues = new Dictionary <string, string> { { Constants.Authentication.ErrorKeyName, errorMessage }, }; try { OAuthErrorHandler.ThrowIfError(responseValues); } catch (OneDriveException exception) { Assert.AreEqual(OneDriveErrorCode.AuthenticationFailure.ToString(), exception.Error.Code, "Unexpected error code."); Assert.AreEqual(errorMessage, exception.Error.Message, "Unexpected error message."); // Rethrow to kick off final validation. throw; } }
public async Task <bool> Claim(Uri uri, string documentTitle) { var authenticationResponseValues = UrlHelper.GetQueryOptions(uri); OAuthErrorHandler.ThrowIfError(authenticationResponseValues); string code; if (authenticationResponseValues != null && authenticationResponseValues.TryGetValue("code", out code)) { using (var httpProvider = new HttpProvider(ProxyTools.CreateHttpClientHandler(), true)) { _accountSession = await _oAuthHelper.RedeemAuthorizationCodeAsync(code, OneDriveHelper.OneDriveClientId, OneDriveHelper.OneDriveClientSecret, this.RedirectionUrl.ToString(), OneDriveHelper.Scopes, httpProvider).ConfigureAwait(false); } } return(_accountSession != null); }
internal async Task <AccountSession> GetAccountSessionAsync() { var requestUriStringBuilder = new StringBuilder(); requestUriStringBuilder.Append(this.ServiceInfo.AuthenticationServiceUrl); requestUriStringBuilder.AppendFormat("{0}={1}", Constants.Authentication.RedirectUriKeyName, this.ServiceInfo.ReturnUrl); requestUriStringBuilder.AppendFormat("&{0}={1}", Constants.Authentication.ClientIdKeyName, this.ServiceInfo.AppId); requestUriStringBuilder.AppendFormat("&{0}={1}", Constants.Authentication.ScopeKeyName, string.Join("%20", this.ServiceInfo.Scopes)); requestUriStringBuilder.AppendFormat("&{0}={1}", Constants.Authentication.ResponseTypeKeyName, Constants.Authentication.TokenResponseTypeValueName); var requestUri = new Uri(requestUriStringBuilder.ToString()); // Don't pass the callbackUri to AuthenticateAsync so we invoke the SSO authentication flow. var authenticationResponseValues = await this.ServiceInfo.WebAuthenticationUi.AuthenticateAsync(requestUri, /* callbackUri */ null); OAuthErrorHandler.ThrowIfError(authenticationResponseValues); return(new AccountSession(authenticationResponseValues, this.ServiceInfo.AppId, AccountType.MicrosoftAccount) { CanSignOut = true }); }
public void ValidateError_WithDescription() { var errorMessage = "This is an error."; var errorDescription = "Error description"; var responseValues = new Dictionary <string, string> { { OAuthConstants.ErrorDescriptionKeyName, errorDescription }, { OAuthConstants.ErrorKeyName, errorMessage }, }; try { OAuthErrorHandler.ThrowIfError(responseValues); } catch (ServiceException exception) { Assert.AreEqual(OAuthConstants.ErrorCodes.AuthenticationFailure, exception.Error.Code, "Unexpected error code."); Assert.AreEqual(errorDescription, exception.Error.Message, "Unexpected error message."); // Re-throw to kick off final validation. throw; } }