CameTooFar

A Nerd's False Positive.

Logout from Microsoft/Yahoo/Google using WebAuthenticationBroker

WebAuthenticationBroker is one of the handy API that I use to implement login in app using common login services like Microsoft, Google and Yahoo. This ensures that you don’t need to worry about implementing your own login functionalities. So how do you logout from these services when the user logout from your app? It’s quite simple, you only needs to send logout request to respective services.

Here are the logout urls for Microsoft/Yahoo/Google.

https://login.live.com/login.srf?wa=wsignout1.0
https://login.yahoo.com/config/login?logout=1
https://www.google.com/accounts/Logout

and in your code:

WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.SilentMode, new Uri(logout-url-here));

Hope this helps.

Debug WebAuthenticationBroker error message

Undoubtedly, WebAuthenticationBroker is one of the best API in WinRT/UWP API stack. It helps you to do OAuth and OpenID authentication without any extra work. We no longer need to use WebView and track the URL redirection to capture the tokens. Instead you can invoke the code from ViewModel also.

Since, we don't have much control on what happens and we rely on the status and result returned by the broker. Sometimes, things get more annoying when you get an error screen as below; but don't have any idea about what caused the issue for real.

Of course, traditional way is to use Fiddler which needs some setup for sure. Thankfully, there is another option too to tract the cause for error. All those error messages will be logged in your Windows Event Viewer. Below is the steps to do that:

  1. Open Event Viewer (eventvwr.exe).
  2. Navigate to Application and Services\Microsoft\Windows\WebAuth.
  3. Rt-click Operational log, and select Enable Log.

There you go!

Now, run the broker again. You can see all the logs.

Hope this will save your day.
Thanks.

Fix: Error on posting data using HttpClient

 Last week, I’s spending some time exploring OneDrive Rest API. While trying to send a POST request for receiving access token, I got a error as - “{"error":"invalid_request","error_description":"The provided request must have content-type 'application/x-www-form-urlencoded'."}”. 

I modified my code further. This time, I got another exception – “Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.” Finally, I figured out the correct way to set the content-type header while sending a POST request using HTTPClient. And, here it is.

HttpClient client = new HttpClient();
StringContent content = new StringContent(BodyContent, Encoding.UTF8, "application/x-www-form-urlencoded");
var responseMessage = await client.PostAsync(Uri, content);

Phew! Hope this helps.

Thanks.