我使用WebAuthenticationBroker实现了google auth,如下所示。它使用相同的谷歌帐户在桌面或表面上工作得非常好但是当我在Xbox上试用它时,它不起作用。
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);
在UWP上,我收到Approval_Code和完整的个人资料信息,但在Xbox上,响应如下所示
{https://accounts.google.com/o/oauth2/approval?as=xxxxxxxx=none&xsrfsign=xxxxxx}
有人知道Xbox的特别之处吗?怎么解决这个问题?
我终于找到了解决方案。问题是在使用此选项时使用WebAuthenticationOptions.None
,它在台式机和表面Windows 10机器上工作正常,但此选项对Xbox One无法正常工作。它不返回授权码。
但是浏览器标题栏总是有这个代码,为了获得这个代码,需要使用WebAuthenticationOptions.UseTitle
。一旦使用响应有一个名为“code
”的元素,你可以解析它如下
var queryStringParams = System.Web.HttpUtility.ParseQueryString(receivedData.ResponseData.Substring(receivedData.ResponseData);
string code= queryStringParams["code"];
当使用WebAuthenticationOptions.None
响应时,没有queryStringcalled“code
”,但作为“approvalCode
”。也存在这种差异。我不知道为什么。但无论如何WebAuthenticationOptions.UseTitle
可用于所有UWP设备。我已经对所有人进行了测试,并且像魅力一样