/// <summary> /// Starts the asynchronous authentication operation with three inputs. /// You can call this method multiple times in a single application or across multiple applications at the same time. /// </summary> /// <param name="options">The options for the authentication operation.</param> /// <param name="requestUri">The starting URI of the web service. This URI must be a secure address of https://.</param> /// <param name="callbackUri">The callback URI that indicates the completion of the web authentication. /// The broker matches this URI against every URI that it is about to navigate to. /// The broker never navigates to this URI, instead the broker returns the control back to the application when the user clicks a link or a web server redirection is made.</param> /// <returns>The way to query the status and get the results of the authentication operation. /// If you are getting an invalid parameter error, the most common cause is that you are not using HTTPS for the requestUri parameter.</returns> /// <remarks>When this method is used, no session state or persisted cookies are retained across multiple calls from the same or different apps. /// This method must be called on the UI thread.</remarks> public static async Task<WebAuthenticationResult> AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri, Uri callbackUri) { #if WINDOWS_UWP || WINDOWS_APP return await Windows.Security.Authentication.Web.WebAuthenticationBroker.AuthenticateAsync((Windows.Security.Authentication.Web.WebAuthenticationOptions)((int)options), requestUri, callbackUri); #elif WINDOWS_PHONE_APP var method = type10.GetRuntimeMethod("AuthenticateAsync", new Type[] { typeof(Windows.Security.Authentication.Web.WebAuthenticationOptions), typeof(Uri), typeof(Uri) }); if (method != null) { IAsyncOperation<Windows.Security.Authentication.Web.WebAuthenticationResult> op = (IAsyncOperation<Windows.Security.Authentication.Web.WebAuthenticationResult>)method.Invoke(null, new object[] { (Windows.Security.Authentication.Web.WebAuthenticationOptions)((int)options), requestUri, callbackUri }); var result = await op; return result; } else { throw new PlatformNotSupportedException(); } #elif WINDOWS_PHONE Result = new WebAuthenticationResult(null, 0, WebAuthenticationStatus.UserCancel); Frame f = Application.Current.RootVisual as Frame; if (f != null) { if (!f.Dispatcher.CheckAccess()) { throw new InvalidOperationException("Must be called on UI thread."); } Handle = new AutoResetEvent(false); Uri navUri = new Uri(string.Format("/InTheHand;component/Security/Authentication/Web/WebAuthenticationPage.xaml?uri={0}&returnUri={1}", Uri.EscapeDataString(requestUri.ToString()), Uri.EscapeDataString(callbackUri.ToString())), UriKind.Relative); f.Navigate(navUri); await Task.Run(new Func<Task>(WaitResponse)); } return Result; #else throw new PlatformNotSupportedException(); #endif }