0

I have implemented google auth using WebAuthenticationBroker like below. It works perfectly fine on Desktop or Surface using same google account but when I try it on Xbox, it doesnt work.

     string authString = "https://accounts.google.com/o/oauth2/auth?client_id=" + Uri.EscapeDataString(ClientID);
                authString += "&scope=openid%20email%20profile";
                authString += $"&redirect_uri={Uri.EscapeDataString(RedirectURI)}";           
                authString += $"&code_challenge={code_challenge}";
                authString += $"&code_challenge_method={code_challenge_method}";
                authString += "&response_type=code";
                authString += "&include_granted_scopes=true";

     string endURL = "https://accounts.google.com/o/oauth2/approval";
   Uri startURI = new Uri(authString);
      Uri endURI = new Uri(endURL);
   var receivedData = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startURI, endURI);

On UWP i receive an Approval_Code and full profile information but on Xbox, response is something like below

{https://accounts.google.com/o/oauth2/approval?as=xxxxxxxx=none&xsrfsign=xxxxxx}

Anyone knows what is special about Xbox one? how to fix this?

Emil
  • 6,411
  • 7
  • 62
  • 112

1 Answers1

0

I finally found a solution. Problem is to use WebAuthenticationOptions.None when using this option, it works fine on desktop and surface Windows 10 machiens but this option doesnt work correctly for Xbox One. it returns no authorization code.

But browser title bar has always this code and in order to obtain this code, WebAuthenticationOptions.UseTitle needs to be used. Once used response has an element called "code" and you can just parse it as below

      var queryStringParams = System.Web.HttpUtility.ParseQueryString(receivedData.ResponseData.Substring(receivedData.ResponseData);

string code= queryStringParams["code"];

When using WebAuthenticationOptions.None response doesnt have queryStringcalled "code" but as "approvalCode". there is also this difference. I dont know why. But anyhow WebAuthenticationOptions.UseTitle can be used for all UWP devices. I have tested on all and works like a charm

Emil
  • 6,411
  • 7
  • 62
  • 112