title: Authenticate against UAG using Windows Phone 8 app
body: <p>I have a very simple scenario - I need my app to automatically authenticate against the UAG gateway. At the moment, I only have a file share application behind the portal, but I'm just trying to do an automatic authentication against the UAG by supplying the user credentials in code. I'm trying to access <code>portal.mylab.com/dummylink</code> - I know this will fail but I want the app to show me it passed the UAG authentication and failed when trying to find this dummylink application</p>
  
  <p>What I have for now is simple, there is just a button in the WP8 app and everything else is hardcoded. I have a simple textblock under the button which shows the response from the website, but I get the authentication page everytime. This is what I have</p>
  
  <pre><code>private void Button_Click(object sender, RoutedEventArgs e)
          {
              System.Uri targetUri = new System.Uri("portal.mylab.com/dummylink");
              HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
              request.CookieContainer = new CookieContainer();
  
             request.Headers["User-Agent"] = "Microsoft Office Mobile";
             request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("testuser" + ":" + "Password1")) + System.Environment.NewLine;
  request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
  
  }
  
  private void ReadWebRequestCallback(IAsyncResult callbackResult)
          {
              HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
  
              HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);
  
  using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
              {
                  string results = httpwebStreamReader.ReadToEnd();
                  Dispatcher.BeginInvoke(() =&gt; TextBlockResults.Text = results);
              }
  }
  </code></pre>
  
  <p>When I look at the textblock, I can see the HTML code being returned for the login page (for a mobile portal), with 2 buttons to login either using a PIN or using credentials. What I expected (or rather wanted) to see is UAG authorization to be successful and get some kind of a "dummylink page not found" type of error. I am supplying the user credentials to UAG but it doesn't seem to be picking them up.</p>
  
  <p>I'm probably missing something very obvious here, and also this is my first time with anything to do with UAG, so please excuse stupid mistakes :)</p>
  
  <p>Thanks in advance</p>