4

This code works fine in my UWP app when running on Windows 10 desktop/mobile, however on Xbox One I am getting an error:

My c# code:

credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
             new Uri("ms-appx:///Assets/client_secrets.json"),
             new[] { "https://www.googleapis.com/auth/plus.profile.emails.read" },
             "user",
             CancellationToken.None);                

return credential.Token.AccessToken;

Here are the steps that are happening:

  1. Click on google login btn
  2. google login screen is loading
  3. I can log into my google account
  4. The login windows asks me to Authorize permissions for the app
  5. Error happens here: I never get the Oauth token and get the following error message: Error:"Success", Description:"The WebAuthenticationBroker didn't return a code or an error. Details:0", Uri:""

Is any one having this issue?

My project.json file:

{
  "dependencies": {
    "Google.Apis": "1.15.0",
    "Google.Apis.Auth": "1.15.0",
    "Google.Apis.Core": "1.15.0",
    "Microsoft.ApplicationInsights": "2.1.0",
    "Microsoft.ApplicationInsights.PersistenceChannel": "1.2.3",
    "Microsoft.ApplicationInsights.WindowsApps": "1.1.1",
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
    "Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0",
    "MvvmLightLibs": "5.3.0",
    "Newtonsoft.Json": "9.0.1",
    "NotificationsExtensions.Win10": "14295.0.1"       
  },
  "frameworks": {
    "uap10.0": {}
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}

Any idea on what I am doing wrong?

Damien
  • 2,911
  • 1
  • 25
  • 47
  • 1
    Have you tried to use [WebAuthenticationBroker](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.security.authentication.web.webauthenticationbroker.aspx) class to implement the auth process? Looks like this API uses this class but failed to get auth code – Franklin Chen - MSFT Aug 09 '16 at 06:22

1 Answers1

1

Like Franklin proposed I went with a good old WebAuthenticationBroker, here the piece of code if someone else is interested:

String GoogleURL = "https://accounts.google.com/o/oauth2/auth?client_id=" 
                            + Uri.EscapeDataString("ABC-DECF1234.apps.googleusercontent.com") 
                            + "&redirect_uri=" + Uri.EscapeDataString("urn:ietf:wg:oauth:2.0:oob") 
                            + "&response_type=code&scope=" + Uri.EscapeDataString("https://www.googleapis.com/auth/plus.profile.emails.read");

Uri StartUri = new Uri(GoogleURL);
Uri EndUri = new Uri("https://accounts.google.com/o/oauth2/approval?");

WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseTitle, StartUri, EndUri);

if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
       {
               return WebAuthenticationResult.ResponseData.ToString();
       }
Damien
  • 2,911
  • 1
  • 25
  • 47
  • How did you solve this probl em? Even using like that response is different on Xbox than desktop. Xbox response doesn't have approvalcode . Did you create different clientid and secret for xbox? – Emil Feb 15 '19 at 06:16