0
我正在制作一个使用OAuth2的UWP应用程序。我正在使用WebAuthenticationBroker类,并且在设备上进行调试时没有问题,但只是更改为释放并运行会导致应用程序在应该打开auth对话框时崩溃。 这里是代码,几乎是他们在MSDN上给你的样板。UWP - WebAuthenticationBroker在发布模式下在设备上崩溃
try {
var webAuthenticationResult = await Windows.Security.Authentication.Web.WebAuthenticationBroker.AuthenticateAsync(Windows.Security.Authentication.Web.WebAuthenticationOptions.None, startURI);
switch (webAuthenticationResult.ResponseStatus) {
case Windows.Security.Authentication.Web.WebAuthenticationStatus.Success:
// Successful authentication.
var uri = new Uri(webAuthenticationResult.ResponseData);
var index = uri.Query.IndexOf('=') + 1;
code = uri.Query.Substring(index);
_accessToken = await GetAccessToken(code);
vault.Add(new PasswordCredential("myApp", "token", Token));
break;
case Windows.Security.Authentication.Web.WebAuthenticationStatus.ErrorHttp:
// HTTP error.
throw new HttpRequestException(webAuthenticationResult.ResponseErrorDetail.ToString());
default:
// Other error.
throw new Exception(webAuthenticationResult.ResponseData.ToString());
}
} catch (Exception ex) {
// Authentication failed. Handle parameter, SSL/TLS, and Network Unavailable errors here.
throw ex;
}
你有什么* App.Entering/LeavingBackground *? – Romasz
@Romasz我不知道,这是大多数谷歌搜索送我。事实证明,我需要传递结束URI的第三个参数。不知道为什么它在调试中没问题,但是......现在看起来一切都很好。只需要摆脱手机顶部的保证金即可。我做了一件事,在项目的属性中,我选择了删除所有数据的选项。我不确定那是否做了什么。 –