简体   繁体   中英

UWP - WebAuthenticationBroker crashes on device in release mode

I am making a UWP app that uses OAuth2. I am using the WebAuthenticationBroker class and it is fine when in debug on the device but just changing to release and running causes the app to crash when it should be opening the auth dialog. Here is the code, pretty much the boilerplate they give you on 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;
        }

It turns out that I needed to pass the third parameter for end URI for this particular API. Not sure why it was ok in debug but... It all seems good now. Just need to get rid of the margin at the top on my phone. I did do one thing, In the properties of the project I selected the option for removing all data. I'm not sure if that did anything though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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