コード例 #1
0
        private async Task RunAsync()
        {
            // Do the background task activity. First, get the authentication context.
            Debug.WriteLine("Getting event details");

            if (!HotspotAuthenticationContext.TryGetAuthenticationContext(_details.EventToken, out _context))
            {
                // The event is not targetting this application. There is no further processing to do.
                Debug.WriteLine("Failed to get event context");
                return;
            }

            byte[] ssid = _context.WirelessNetworkId;
            Debug.WriteLine("SSID: " + System.Text.UTF8Encoding.UTF8.GetString(ssid, 0, ssid.Length));

            if (ConfigStore.UseNativeWISPr)
            {
                // Following code can be used if using native WISPr implementation. Please note that
                // following HotspotAuthenticationContext properties only work on windows and not on windows phone.
                // On Windows Phone they return un-useful strings
                // Developers are expected to implement their own WISPr implementation on Phone

                Debug.WriteLine("AuthenticationUrl: " + _context.AuthenticationUrl.OriginalString);
                Debug.WriteLine("RedirectMessageUrl: " + _context.RedirectMessageUrl.OriginalString);
                Debug.WriteLine("RedirectMessageXml: " + _context.RedirectMessageXml.GetXml());

                // In this sample, the AuthenticationUrl is always checked in the background task handler
                // to avoid launching the foreground app in case the authentication host is not trusted.
                if (ConfigStore.AuthenticationHost != _context.AuthenticationUrl.Host)
                {
                    // Hotspot is not using the trusted authentication server.
                    // Abort authentication and disconnect.
                    Debug.WriteLine("Authentication server is untrusted");
                    _context.AbortAuthentication(ConfigStore.MarkAsManualConnect);
                    return;
                }
            }

            // Run the appropriate scenario selected by the foreground app.
            if (ConfigStore.AuthenticateThroughBackgroundTask)
            {
                await AuthenticateInBackgroundAsync();
            }
            else
            {
                ContinueAuthenticationInForeground();
            }
            return;
        }
 /// <summary>
 /// This is the click handler for the 'Abort' button.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AbortButton_Click(object sender, RoutedEventArgs args)
 {
     try
     {
         authenticationContext.AbortAuthentication(ConfigStore.MarkAsManualConnect);
         rootPage.NotifyUser("Authentication aborted", NotifyType.StatusMessage);
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
     }
     ClearAuthenticationToken();
 }
コード例 #3
0
 /// <summary>
 /// This is the click handler for the 'Abort' button.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AbortButton_Click(object sender, RoutedEventArgs args)
 {
     authenticationContext.AbortAuthentication(ConfigStore.MarkAsManualConnect);
     rootPage.NotifyUser("Authentication aborted", NotifyType.StatusMessage);
     ClearAuthenticationToken();
 }