繁体   English   中英

UWP-WebAuthenticationBroker在发布模式下在设备上崩溃

[英]UWP - WebAuthenticationBroker crashes on device in release mode

我正在制作使用OAuth2的UWP应用。 我使用的是WebAuthenticationBroker类,在设备上进行调试时很好,但是更改为发行并运行会导致应用程序在应打开身份验证对话框时崩溃。 这是代码,几乎是他们在MSDN上给您的样板。

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;
        }

事实证明,我需要为此特定API传递第三个参数作为结束URI。 不确定为什么在调试中还可以,但是...现在看来一切都很好。 只需摆脱手机顶部的边距即可。 我确实做了一件事,在项目的属性中,我选择了删除所有数据的选项。 我不确定这是否有任何作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM